snowplow/snowplow-javascript-tracker

View on GitHub

Showing 153 of 352 total issues

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

  function enqueueRequest(request: Payload, url: string) {
    configCollectorUrl = url + path;
    const eventTooBigWarning = (bytes: number, maxBytes: number) =>
      LOG.warn('Event (' + bytes + 'B) too big, max is ' + maxBytes);

Severity: Minor
Found in libraries/browser-tracker-core/src/tracker/out_queue.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 flush has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            const flush = (): void => {
              const bufferCopy = buffer;
              buffer = [];
              if (bufferCopy.length === 0) {
                return;
          Severity: Minor
          Found in trackers/node-tracker/src/got_emitter.ts - About 1 hr to fix

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

            export function trackingOptionsParser(id: string, trackingOptions?: MediaTrackingOptions): TrackingOptions {
              const defaults: TrackingOptions = {
                id: id,
                captureEvents: DefaultEvents,
                progress: {
            Severity: Minor
            Found in plugins/browser-plugin-media-tracking/src/helperFunctions.ts - About 1 hr to fix

              Function setXhrCallbacks has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                function setXhrCallbacks(xhr: XMLHttpRequest, numberToSend: number, batch: EventBatch) {
                  xhr.onreadystatechange = function () {
                    if (xhr.readyState === 4) {
                      clearTimeout(xhrTimeout);
                      if (isSuccessfulRequest(xhr.status)) {
              Severity: Minor
              Found in libraries/browser-tracker-core/src/tracker/out_queue.ts - About 1 hr to fix

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

                export function globalContexts(): GlobalContexts {
                  let globalPrimitives: Array<ContextPrimitive> = [];
                  let conditionalProviders: Array<ConditionalContextProvider> = [];
                
                  /**
                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 findMediaElementChild has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                function findMediaElementChild(el: Element): SearchResult {
                  for (let tag of Object.keys(TAG)) {
                    let elem = el.getElementsByTagName(tag);
                    if (elem.length === 1) {
                      if (isAudioElement(elem[0])) return { el: elem[0] };
                Severity: Minor
                Found in plugins/browser-plugin-media-tracking/src/findMediaElement.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 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 getYouTubeEntities has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function getYouTubeEntities(player: YT.Player, urlParameters: UrlParameters, eventData?: EventData): MediaEntities {
                  const spherical: YT.SphericalProperties = player.getSphericalProperties();
                  const playerStates: Record<number, boolean> = {
                    [YT.PlayerState.BUFFERING]: false,
                    [YT.PlayerState.CUED]: false,
                Severity: Minor
                Found in plugins/browser-plugin-youtube-tracking/src/buildYouTubeEvent.ts - About 1 hr to fix

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

                    function getOptimizelyStateContexts() {
                      var experimentIds = [];
                      var experiments = getOptimizelyData('experiments');
                      if (experiments) {
                        for (var key in experiments) {
                  Severity: Minor
                  Found in plugins/browser-plugin-optimizely/src/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

                        Consider simplifying this complex logical expression.
                        Open

                          if (
                            plugins.optimizely &&
                            (optimizelySummary ||
                              optimizelyExperiments ||
                              optimizelyStates ||
                        Severity: Critical
                        Found in trackers/javascript-tracker/src/features.ts - About 1 hr to fix

                          Function processClick has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          function processClick(tracker: BrowserTracker, sourceElement: Element, context?: DynamicContext | null) {
                            let parentElement, tag, elementId, elementClasses, elementTarget, elementContent;
                          
                            while (
                              (parentElement = sourceElement.parentElement) !== null &&
                          Severity: Minor
                          Found in plugins/browser-plugin-link-click-tracking/src/index.ts - About 1 hr to fix

                            Function _run has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            function _run() {
                                const [nodePath /* Ex: /bin/node */, scriptPath /* /repo/common/scripts/install-run-rush.js */, ...packageBinArgs /* [build, --to, myproject] */] = process.argv;
                                // Detect if this script was directly invoked, or if the install-run-rushx script was invokved to select the
                                // appropriate binary inside the rush package to run
                                const scriptName = path.basename(scriptPath);
                            Severity: Minor
                            Found in common/scripts/install-run-rush.js - About 1 hr to fix

                              Function track has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  function track(
                                    pb: PayloadBuilder,
                                    context?: Array<SelfDescribingJson> | null,
                                    timestamp?: Timestamp | null
                                  ): Payload {
                              Severity: Minor
                              Found in libraries/tracker-core/src/core.ts - About 1 hr to fix

                                Function enableMediaTracking has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                export function enableMediaTracking(args: { id: string; options?: MediaTrackingOptions }) {
                                  const conf: TrackingOptions = trackingOptionsParser(args.id, args.options);
                                
                                  // Some events have additional effects/need to perform checks before running mediaPlayerEvent
                                  const eventsWithOtherFunctions: Record<string, Function> = {
                                Severity: Minor
                                Found in plugins/browser-plugin-media-tracking/src/index.ts - About 1 hr to fix

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

                                  export function enableMediaTracking(args: { id: string; options?: MediaTrackingOptions }) {
                                    const conf: TrackingOptions = trackingOptionsParser(args.id, args.options);
                                  
                                    // Some events have additional effects/need to perform checks before running mediaPlayerEvent
                                    const eventsWithOtherFunctions: Record<string, Function> = {
                                  Severity: Minor
                                  Found in plugins/browser-plugin-media-tracking/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