Skip to content

Commit

Permalink
fix Percentage and add Pixel Depth and Timing events with gtag.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kejjang committed Jul 19, 2018
1 parent 414b06e commit 7844208
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions jquery.scrolldepth.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,35 @@

var command = options.trackerName ? (options.trackerName + '.send') : 'send';

if (standardEventHandler) {
if (globalSiteTag) {

gtag('event', action, {
'event_category': 'Scroll Depth',
'event_label': label,
'value': 1,
'non_interaction': options.nonInteraction
});

if (options.pixelDepth && arguments.length > 2 && scrollDistance > lastPixelDepth) {
lastPixelDepth = scrollDistance;
gtag('event', 'Pixel Depth', {
'event_category': 'Scroll Depth',
'event_label': rounded(scrollDistance),
'value': 1,
'non_interaction': options.nonInteraction
});
}

if (options.userTiming && arguments.length > 3) {
gtag('event', 'timing_complete', {
'event_category': 'Scroll Depth',
'name': action,
'event_label': label,
'value': timing
});
}

} else if (standardEventHandler) {

standardEventHandler({'event': 'ScrollDistance', 'eventCategory': 'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventValue': 1, 'eventNonInteraction': options.nonInteraction});

Expand All @@ -115,14 +143,6 @@
standardEventHandler({'event': 'ScrollTiming', 'eventCategory': 'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventTiming': timing});
}

if (globalSiteTag) {
gtag('event', 'scroll_depth', {
'category': 'Scroll Depth',
'scroll_distance': label,
'px_distance': scrollDistance
});
}

} else {

if (universalGA) {
Expand Down

0 comments on commit 7844208

Please sign in to comment.