snowplow/snowplow-javascript-tracker

View on GitHub

Showing 145 of 325 total issues

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 globalContexts has 80 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function globalContexts(): GlobalContexts {
      let globalPrimitives: Array<ContextPrimitive> = [];
      let conditionalProviders: Array<ConditionalContextProvider> = [];
      let namedPrimitives: Record<string, ContextPrimitive> = {};
      let namedConditionalProviders: Record<string, ConditionalContextProvider> = {};
    Severity: Major
    Found in libraries/tracker-core/src/contexts.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 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 compareProvider has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

        function compareProvider(
          a: ConditionalContextProvider | ContextPrimitive,
          b: ConditionalContextProvider | ContextPrimitive
        ): boolean {
          if (isConditionalContextProvider(a)) {
        Severity: Minor
        Found in libraries/tracker-core/src/contexts.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

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

          import { EventStore, newInMemoryEventStore } from '../event_store';
          import { Payload } from '../payload';
          import { EmitterRequest, newEmitterRequest } from './emitter_request';
          import { EmitterEvent, newEmitterEvent } from './emitter_event';
          import { newEventStorePayload } from '../event_store_payload';
          Severity: Minor
          Found in libraries/tracker-core/src/emitter/index.ts - About 2 hrs to fix

            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 waitForElement has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                Open

                export function waitForElement(config: StringConfig, callback: (element: ElementConfig) => void) {
                  const { el, err } = findMediaElement(config.video);
                  if (err) {
                    LOG.info(`${err}. Waiting for element to be added to the DOM.`);
                  }
                Severity: Minor
                Found in plugins/browser-plugin-media-tracking/src/findElem.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 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 newCookie has 53 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function newCookie(name: string): Cookie {
                      let flushTimer: ReturnType<typeof setTimeout> | undefined;
                      let lastSetValueArgs: Parameters<typeof setValue> | undefined;
                      let cacheExpireAt: Date | undefined;
                      let flushed = true;
                    Severity: Major
                    Found in libraries/browser-tracker-core/src/tracker/cookie_storage.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

                        File api.ts has 253 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        /*
                         * Copyright (c) 2022 Snowplow Analytics Ltd, 2010 Anthon Pang
                         * All rights reserved.
                         *
                         * Redistribution and use in source and binary forms, with or without
                        Severity: Minor
                        Found in trackers/browser-tracker/src/api.ts - About 2 hrs to fix

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

                          /*
                           * Copyright (c) 2022 Snowplow Analytics Ltd, 2010 Anthon Pang
                           * All rights reserved.
                           *
                           * Redistribution and use in source and binary forms, with or without
                          Severity: Minor
                          Found in libraries/browser-tracker-core/src/helpers/index.ts - About 2 hrs to fix

                            Function parseIdCookie has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            export function parseIdCookie(
                              id: string | undefined,
                              domainUserId: string,
                              memorizedSessionId: string,
                              memorizedVisitCount: number
                            Severity: Major
                            Found in libraries/browser-tracker-core/src/tracker/id_cookie.ts - About 2 hrs to fix

                              Function createSharedState has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

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