snowplow/snowplow-javascript-tracker

View on GitHub

Showing 145 of 325 total issues

Function isRuleSet has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

export function isRuleSet(input: unknown): input is Record<string, unknown> {
  const ruleSet = input as Record<string, unknown>;
  let ruleCount = 0;
  if (input != null && typeof input === 'object' && !Array.isArray(input)) {
    if (Object.prototype.hasOwnProperty.call(ruleSet, 'accept')) {
Severity: Minor
Found in libraries/tracker-core/src/contexts.ts - About 1 hr 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 newCookieStorage has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function newCookieStorage(): AsyncCookieStorage {
  let cache: Record<string, Cookie> = {};

  function getOrInitCookie(name: string): Cookie {
    if (!cache[name]) {
Severity: Minor
Found in libraries/browser-tracker-core/src/tracker/cookie_storage.ts - About 1 hr to fix

    Function WebVitalsPlugin has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function WebVitalsPlugin(pluginOptions: WebVitalsPluginOptions = defaultPluginOptions): BrowserPlugin {
      const webVitalsObject: Record<string, unknown> = {};
      const options = { ...defaultPluginOptions, ...pluginOptions };
      let trackerId: string;
      let webVitalsScript: HTMLScriptElement | undefined;
    Severity: Minor
    Found in plugins/browser-plugin-web-vitals/src/index.ts - About 1 hr to fix

      Function logger has 38 lines of code (exceeds 25 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 1 hr to fix

        Function jsonInterceptor has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          function jsonInterceptor(encodeBase64: boolean): JsonProcessor {
            const log = (jsonType: string, data: SelfDescribingJson) => {
              const schemaParts = getSchemaParts(data['schema']);
              debug(colours.event(), 'Event', [
                '%c%s%c%s%c%s\n%o',
        Severity: Minor
        Found in plugins/browser-plugin-debugger/src/index.ts - About 1 hr to fix

          Function updateForThisEvent has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            updateForThisEvent(
              eventType: MediaEventType,
              player: MediaPlayer,
              ad?: MediaAdUpdate,
              adBreak?: MediaPlayerAdBreakUpdate
          Severity: Minor
          Found in plugins/browser-plugin-media/src/adTracking.ts - About 1 hr 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 executeRequest has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            async function executeRequest(request: EmitterRequest): Promise<RequestResult> {
              const fetchRequest = request.toRequest();
              if (fetchRequest === undefined) {
                throw new Error('Empty batch');
              }
          Severity: Minor
          Found in libraries/tracker-core/src/emitter/index.ts - About 1 hr to fix

            Function FocalMeterPlugin has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function FocalMeterPlugin(): BrowserPlugin {
              let LOG: Logger;
              let lastUserId: string | undefined | null;
              let trackerId: string;
            
            
            Severity: Minor
            Found in plugins/browser-plugin-focalmeter/src/index.ts - About 1 hr to fix

              Function update has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                update(
                  trackEvent: (event: EventWithContext) => void,
                  mediaEvent?: MediaEvent,
                  customEvent?: SelfDescribingJson,
                  player?: MediaPlayerUpdate,
              Severity: Minor
              Found in plugins/browser-plugin-media/src/mediaTracking.ts - About 1 hr to fix

                Function FocalMeterPlugin has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                export function FocalMeterPlugin(): BrowserPlugin {
                  let LOG: Logger;
                  let lastUserId: string | undefined | null;
                  let trackerId: string;
                
                
                Severity: Minor
                Found in plugins/browser-plugin-focalmeter/src/index.ts - About 1 hr 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 payloadBuilder has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                export function payloadBuilder(): PayloadBuilder {
                  const dict: Payload = {},
                    allJson: EventJson = [],
                    jsonForProcessing: EventJson = [],
                    contextEntitiesForProcessing: SelfDescribingJson[] = [];
                Severity: Minor
                Found in libraries/tracker-core/src/payload.ts - About 1 hr 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 WebVitalsPlugin has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                export function WebVitalsPlugin(pluginOptions: WebVitalsPluginOptions = defaultPluginOptions): BrowserPlugin {
                  const webVitalsObject: Record<string, unknown> = {};
                  const options = { ...defaultPluginOptions, ...pluginOptions };
                  let trackerId: string;
                  let webVitalsScript: HTMLScriptElement | undefined;
                Severity: Minor
                Found in plugins/browser-plugin-web-vitals/src/index.ts - About 1 hr 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 newEmitterEvent has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                export function newEmitterEvent(eventStorePayload: EventStorePayload): EmitterEvent {
                  let querystring: string | null = null;
                  let postBody: Record<string, unknown> | null = null;
                  let byteCountGET: number | null = null;
                  let byteCountPOST: number | null = null;
                Severity: Minor
                Found in libraries/tracker-core/src/emitter/emitter_event.ts - About 1 hr 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 activateBrowserPlugin has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    activateBrowserPlugin: (tracker) => {
                      trackerId = tracker.id;
                      _trackers[trackerId] = tracker;
                
                      function sendWebVitals() {
                Severity: Minor
                Found in plugins/browser-plugin-web-vitals/src/index.ts - About 1 hr to fix

                  Function continueFlush has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    async function continueFlush() {
                      await callIdService();
                  
                      const request = newEmitterRequestWithConfig();
                      const eventStoreIterator = eventStore.iterator();
                  Severity: Minor
                  Found in libraries/tracker-core/src/emitter/index.ts - About 1 hr to fix

                    Function base64encode has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export function base64encode(data: string): string {
                      // discuss at: http://phpjs.org/functions/base64_encode/
                      // original by: Tyler Akins (http://rumkin.com)
                      // improved by: Bayron Guevara
                      // improved by: Thunder.m
                    Severity: Minor
                    Found in libraries/tracker-core/src/base64.ts - About 1 hr to fix

                      Function enableGeolocationContext has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      export function enableGeolocationContext(trackers: Array<string> = Object.keys(_trackers)) {
                        const navigatorAlias = navigator;
                      
                        trackers.forEach((t) => {
                          //Mark as enabled
                      Severity: Minor
                      Found in plugins/browser-plugin-geolocation/src/index.ts - About 1 hr to fix

                        Function matchSchemaAgainstRuleSet has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        export function matchSchemaAgainstRuleSet(ruleSet: RuleSet, schema: string): boolean {
                          let rejectCount = 0;
                          let acceptCount = 0;
                          const acceptRules = ruleSet['accept'];
                          if (Array.isArray(acceptRules)) {
                        Severity: Minor
                        Found in libraries/tracker-core/src/contexts.ts - About 1 hr to fix

                          Function buildYouTubeEntity has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          export function buildYouTubeEntity(conf: TrackingOptions): SelfDescribingJson<YouTubeEntity> | null {
                            const { player, urlParameters = {} } = conf;
                          
                            if (!player) return null;
                          
                          
                          Severity: Minor
                          Found in plugins/browser-plugin-youtube-tracking/src/entities.ts - About 1 hr to fix

                            Function DebuggerPlugin has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                            Open

                            export function DebuggerPlugin(logLevel: LOG_LEVEL = LOG_LEVEL.debug): BrowserPlugin {
                              let LOG: Logger;
                              let tracker: BrowserTracker;
                              let eventColour: string;
                            
                            
                            Severity: Minor
                            Found in plugins/browser-plugin-debugger/src/index.ts - About 1 hr 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

                            Severity
                            Category
                            Status
                            Source
                            Language