snowplow/snowplow-javascript-tracker

View on GitHub

Showing 153 of 352 total issues

Function executeQueue has 105 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  function executeQueue(sync: boolean = false) {
    // Failsafe in case there is some way for a bad value like "null" to end up in the outQueue
    while (outQueue.length && typeof outQueue[0] !== 'string' && typeof outQueue[0] !== 'object') {
      outQueue.shift();
    }
Severity: Major
Found in libraries/browser-tracker-core/src/tracker/out_queue.ts - About 4 hrs to fix

    Function trackerCore has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    export function trackerCore(configuration: CoreConfiguration = {}): TrackerCore {
      function newCore(base64: boolean, corePlugins: Array<CorePlugin>, callback?: (PayloadData: PayloadBuilder) => void) {
        const pluginContextsHelper: PluginContexts = pluginContexts(corePlugins),
          globalContextsHelper: GlobalContexts = globalContexts();
    
    
    Severity: Minor
    Found in libraries/tracker-core/src/core.ts - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function gotEmitter has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    export function gotEmitter(
      endpoint: string,
      protocol: HttpProtocol = HttpProtocol.HTTPS,
      port?: number,
      method?: HttpMethod,
    Severity: Minor
    Found in trackers/node-tracker/src/got_emitter.ts - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function BrowserFeaturesPlugin has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    export function BrowserFeaturesPlugin(): BrowserPlugin {
      return {
        activateBrowserPlugin: (tracker: BrowserTracker) => {
          const navigatorAlias = navigator;
          // General plugin detection
    Severity: Minor
    Found in plugins/browser-plugin-browser-features/src/index.ts - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function DebuggerPlugin has 81 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function DebuggerPlugin(logLevel: LOG_LEVEL = LOG_LEVEL.debug): BrowserPlugin {
      let LOG: Logger;
      let tracker: BrowserTracker;
      let eventColour: string;
    
    
    Severity: Major
    Found in plugins/browser-plugin-debugger/src/index.ts - About 3 hrs to fix

      Function addPlugin has 76 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        function addPlugin(parameterArray: Array<unknown>, trackerIdentifiers: Array<string>) {
          function postScriptHandler(scriptSrc: string) {
            if (Object.prototype.hasOwnProperty.call(pendingPlugins, scriptSrc)) {
              windowAlias.clearTimeout(pendingPlugins[scriptSrc].timeout);
              delete pendingPlugins[scriptSrc];
      Severity: Major
      Found in trackers/javascript-tracker/src/in_queue.ts - About 3 hrs to fix

        Function gotEmitter has 76 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function gotEmitter(
          endpoint: string,
          protocol: HttpProtocol = HttpProtocol.HTTPS,
          port?: number,
          method?: HttpMethod,
        Severity: Major
        Found in trackers/node-tracker/src/got_emitter.ts - About 3 hrs to fix

          Function updateDurationStats has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
          Open

            private updateDurationStats(log: Log) {
              // if ad was playing until now and it was a linear ad, don't add the duration stats
              let wasPlayingAd = this.lastAdUpdateAt !== undefined;
              const shouldCountStats = (!wasPlayingAd || !log.linearAd) ?? true;
              if (!shouldCountStats) {
          Severity: Minor
          Found in plugins/browser-plugin-media/src/sessionStats.ts - About 2 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function logger has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
          Open

          function logger(logLevel: LOG_LEVEL = LOG_LEVEL.warn): Logger {
            function setLogLevel(level: LOG_LEVEL) {
              if (LOG_LEVEL[level]) {
                logLevel = level;
              } else {
          Severity: Minor
          Found in libraries/tracker-core/src/logger.ts - About 2 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function getBrowserDataPlugin has 67 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              function getBrowserDataPlugin() {
                const anonymizeOr = (value?: string | number | null) => (configAnonymousTracking ? null : value);
                const anonymizeSessionOr = (value?: string | number | null) =>
                  configAnonymousSessionTracking ? value : anonymizeOr(value);
          
          
          Severity: Major
          Found in libraries/browser-tracker-core/src/tracker/index.ts - About 2 hrs to fix

            Function OutQueueManager has 20 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              id: string,
              sharedSate: SharedState,
              useLocalStorage: boolean,
              eventMethod: string | boolean,
              postPath: string,
            Severity: Major
            Found in libraries/browser-tracker-core/src/tracker/out_queue.ts - About 2 hrs to fix

              File index.ts has 268 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              /*
               * Copyright (c) 2022 Snowplow Analytics Ltd
               * All rights reserved.
               *
               * Redistribution and use in source and binary forms, with or without
              Severity: Minor
              Found in plugins/browser-plugin-youtube-tracking/src/index.ts - About 2 hrs to fix

                Function _copyAndTrimNpmrcFile has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                Open

                function _copyAndTrimNpmrcFile(logger, sourceNpmrcPath, targetNpmrcPath) {
                    logger.info(`Transforming ${sourceNpmrcPath}`); // Verbose
                    logger.info(`  --> "${targetNpmrcPath}"`);
                    let npmrcFileLines = fs.readFileSync(sourceNpmrcPath).toString().split('\n');
                    npmrcFileLines = npmrcFileLines.map((line) => (line || '').trim());
                Severity: Minor
                Found in common/scripts/install-run.js - About 2 hrs to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function trackingOptionsParser has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                Open

                export function trackingOptionsParser(id: string | YT.Player, conf?: MediaTrackingOptions): TrackingOptions {
                  const player = typeof id === 'string' ? undefined : id;
                  const elementId = typeof id === 'string' ? id : id.getIframe().id;
                  const defaultBoundaries = [10, 25, 50, 75];
                  const defaultUpdateRate = 500;
                Severity: Minor
                Found in plugins/browser-plugin-youtube-tracking/src/index.ts - About 2 hrs to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function beforeTrack has 60 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        beforeTrack: (payloadBuilder: PayloadBuilder) => {
                          const existingSession = getSnowplowCookieValue('ses'),
                            idCookie = loadDomainUserIdCookie();
                
                          const isFirstEventInSession = eventIndexFromIdCookie(idCookie) === 0;
                Severity: Major
                Found in libraries/browser-tracker-core/src/tracker/index.ts - About 2 hrs to fix

                  Function GaCookiesPlugin has 57 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export function GaCookiesPlugin(pluginOptions: GACookiesPluginOptions = defaultPluginOptions): BrowserPlugin {
                    return {
                      contexts: () => {
                        const contexts: SelfDescribingJson<Record<string, unknown>>[] = [];
                        const { ga4, ga4MeasurementId, ua, cookiePrefix } = { ...defaultPluginOptions, ...pluginOptions };
                  Severity: Major
                  Found in plugins/browser-plugin-ga-cookies/src/index.ts - About 2 hrs to fix

                    Function createSharedState has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                    Open

                    export function createSharedState(): SharedState {
                      const sharedState = new SharedState(),
                        documentAlias = document,
                        windowAlias = window;
                    
                    
                    Severity: Minor
                    Found in libraries/browser-tracker-core/src/state.ts - About 2 hrs to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Function payloadJsonProcessor has 55 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export function payloadJsonProcessor(encodeBase64: boolean): JsonProcessor {
                      return (
                        payloadBuilder: PayloadBuilder,
                        jsonForProcessing: EventJson,
                        contextEntitiesForProcessing: SelfDescribingJson[]
                    Severity: Major
                    Found in libraries/tracker-core/src/payload.ts - About 2 hrs to fix

                      Function constructNavigationTimingContext has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      export function constructNavigationTimingContext(
                        performanceNavigationTimingInstance: PerformanceNavigationTimingContext
                      ) {
                        const performanceNavigationKeys = [
                          'entryType',
                      Severity: Major
                      Found in plugins/browser-plugin-performance-navigation-timing/src/contexts.ts - About 2 hrs to fix

                        Function contexts has 53 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            contexts: () => {
                              const contexts: SelfDescribingJson<Record<string, unknown>>[] = [];
                              const { ga4, ga4MeasurementId, ua, cookiePrefix } = { ...defaultPluginOptions, ...pluginOptions };
                              const GA_USER_COOKIE = '_ga';
                              const GA4_MEASUREMENT_ID_PREFIX = 'G-';
                        Severity: Major
                        Found in plugins/browser-plugin-ga-cookies/src/index.ts - About 2 hrs to fix
                          Severity
                          Category
                          Status
                          Source
                          Language