Comments (4)
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.
Cool - thanks again for maintaining this library.
from scroll-depth.
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.
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)
- Scroll tracking is not fiering
- please update bower to get v1.0 HOT 2
- Specify page we track HOT 2
- Integrate with Google Tag Manager HOT 2
- Correct way to separate the scrolling trackers on different pages HOT 1
- Correct way to implement using GTM? HOT 8
- Latest Version with GTM - No dataLayer pushes HOT 7
- Install scrolldepth to multiple pages of the website.
- gtag.js
- Surprisingly low number of events HOT 6
- Feature request HOT 5
- Custom names for event category, action, label HOT 1
- Any common issues that would stop any events registering in GA ? HOT 9
- Version bump missed HOT 1
- Current minified version doesn't work HOT 2
- ScrollTiming event doesn't use nonInteraction variable HOT 2
- Update npm version to 1.2 HOT 1
- WordPress Plugin Update HOT 2
- Not firing when using just gtags.js - Global Site Tag HOT 3
- The non-jQuery version seems unable to track in gtag.js HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scroll-depth.