Giter Club home page Giter Club logo

Comments (4)

robflaherty avatar robflaherty commented on August 30, 2024 1

Hi,
Sorry, I left the bug description brief because this was just a reminder for myself. :)

The problem was this line: standardEventHandler = dataLayer.push; which works after GTM redefines dataLayer but not before when it's still an array. Simply wrapping it like this should fix:

standardEventHandler = function(data) {
  dataLayer.push(data);
}

Testing now and will push to master later today. Thanks.

from scroll-depth.

bmd avatar bmd commented on August 30, 2024 1

Cool - thanks again for maintaining this library.

from scroll-depth.

bmd avatar bmd commented on August 30, 2024

dataLayer shouldn't be touched by GA - it's the array-like data object used by GTM. On a page without GTM included, typeof(dataLayer); -> "undefined"

You should be able use the standard dataLayer = dataLayer || [] pattern to initialize it and avoid a race condition on the push method if you need to push something onto it ahead of GTM being initialized but can't guarantee the order in which those things happen.

It seems like the real potential risk for a race condition is here since you aren't checking for the presence of the object you're firing an event to on the actual firing of the event. I think this might also cause a problem if you safe-initialized dataLayer as above and it had type "object" with a valid method push()

from scroll-depth.

robflaherty avatar robflaherty commented on August 30, 2024

btw, much of this needs to be rewritten. right now i just wanted to get a quick fix out. when i rewrite it i agree it'd be smart to make this more robust and check for the method presence before firing the event.

from scroll-depth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.