snowplow/snowplow-javascript-tracker

View on GitHub

Showing 353 of 353 total issues

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 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 _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 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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        export function trackMediaAdStart(
          args: MediaTrackArguments & MediaTrackAdBreakArguments & MediaTrackAdArguments & CommonMediaEventProperties,
          trackers: Array<string> = Object.keys(_trackers)
        ) {
          track({ mediaEvent: { type: MediaEventType.AdStart } }, args, trackers);
        Severity: Major
        Found in plugins/browser-plugin-media/src/api.ts and 1 other location - About 2 hrs to fix
        plugins/browser-plugin-media/src/api.ts on lines 490..495

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 81.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        export function trackMediaAdComplete(
          args: MediaTrackArguments & MediaTrackAdBreakArguments & MediaTrackAdArguments & CommonMediaEventProperties,
          trackers: Array<string> = Object.keys(_trackers)
        ) {
          track({ mediaEvent: { type: MediaEventType.AdComplete } }, args, trackers);
        Severity: Major
        Found in plugins/browser-plugin-media/src/api.ts and 1 other location - About 2 hrs to fix
        plugins/browser-plugin-media/src/api.ts on lines 376..381

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 81.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        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

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

              var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
                  Object.defineProperty(o, "default", { enumerable: true, value: v });
              }) : function(o, v) {
                  o["default"] = v;
              });
              Severity: Major
              Found in common/scripts/install-run.js and 1 other location - About 2 hrs to fix
              common/scripts/install-run-rush.js on lines 15..19

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 78.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

              export function trackMediaAdBreakStart(
                args: MediaTrackArguments & MediaTrackAdBreakArguments & CommonMediaEventProperties,
                trackers: Array<string> = Object.keys(_trackers)
              ) {
                track({ mediaEvent: { type: MediaEventType.AdBreakStart } }, args, trackers);
              Severity: Major
              Found in plugins/browser-plugin-media/src/api.ts and 1 other location - About 2 hrs to fix
              plugins/browser-plugin-media/src/api.ts on lines 363..368

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 78.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

              var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
                  Object.defineProperty(o, "default", { enumerable: true, value: v });
              }) : function(o, v) {
                  o["default"] = v;
              });
              Severity: Major
              Found in common/scripts/install-run-rush.js and 1 other location - About 2 hrs to fix
              common/scripts/install-run.js on lines 15..19

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 78.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

              export function trackMediaAdBreakEnd(
                args: MediaTrackArguments & MediaTrackAdBreakArguments & CommonMediaEventProperties,
                trackers: Array<string> = Object.keys(_trackers)
              ) {
                track({ mediaEvent: { type: MediaEventType.AdBreakEnd } }, args, trackers);
              Severity: Major
              Found in plugins/browser-plugin-media/src/api.ts and 1 other location - About 2 hrs to fix
              plugins/browser-plugin-media/src/api.ts on lines 350..355

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 78.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              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

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                export interface AddToCartEvent {
                  /** A Product Stock Keeping Unit (SKU) */
                  sku: string;
                  /** The number added to the cart */
                  quantity: number;
                Severity: Major
                Found in libraries/tracker-core/src/core.ts and 1 other location - About 2 hrs to fix
                libraries/tracker-core/src/core.ts on lines 1109..1122

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 77.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                export interface RemoveFromCartEvent {
                  /** A Product Stock Keeping Unit (SKU) */
                  sku: string;
                  /** The number removed from the cart */
                  quantity: number;
                Severity: Major
                Found in libraries/tracker-core/src/core.ts and 1 other location - About 2 hrs to fix
                libraries/tracker-core/src/core.ts on lines 1064..1077

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 77.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                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

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

                  export function globalContexts(): GlobalContexts {
                    let globalPrimitives: Array<ContextPrimitive> = [];
                    let conditionalProviders: Array<ConditionalContextProvider> = [];
                  
                    /**
                  Severity: Major
                  Found in libraries/tracker-core/src/contexts.ts - About 2 hrs to fix
                    Severity
                    Category
                    Status
                    Source
                    Language