Skip to content

Commit

Permalink
merging PR #114; version update
Browse files Browse the repository at this point in the history
  • Loading branch information
robflaherty committed Jul 3, 2020
1 parent faee09b commit ac54006
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 28 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "scroll-depth",
"main": "jquery.scrolldepth.js",
"version": "1.1.0",
"version": "1.2.0",
"homepage": "http://scrolldepth.parsnip.io",
"authors": [
"Rob Flaherty"
Expand Down
32 changes: 16 additions & 16 deletions jquery.scrolldepth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* @preserve
* jquery.scrolldepth.js | v1.0
* Copyright (c) 2016 Rob Flaherty (@robflaherty)
* jquery.scrolldepth.js | v1.2.0
* Copyright (c) 2020 Rob Flaherty (@robflaherty)
* Licensed under the MIT and GPL licenses.
*/

Expand Down Expand Up @@ -102,7 +102,20 @@

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

if (globalSiteTag) {
if (standardEventHandler) {

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

if (options.pixelDepth && arguments.length > 2 && scrollDistance > lastPixelDepth) {
lastPixelDepth = scrollDistance;
standardEventHandler({'event': 'ScrollDistance', 'eventCategory': 'Scroll Depth', 'eventAction': 'Pixel Depth', 'eventLabel': rounded(scrollDistance), 'eventValue': 1, 'eventNonInteraction': options.nonInteraction});
}

if (options.userTiming && arguments.length > 3) {
standardEventHandler({'event': 'ScrollTiming', 'eventCategory': 'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventTiming': timing});
}

} else if (globalSiteTag) {

gtag('event', action, {
'event_category': 'Scroll Depth',
Expand Down Expand Up @@ -130,19 +143,6 @@
});
}

} else if (standardEventHandler) {

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

if (options.pixelDepth && arguments.length > 2 && scrollDistance > lastPixelDepth) {
lastPixelDepth = scrollDistance;
standardEventHandler({'event': 'ScrollDistance', 'eventCategory': 'Scroll Depth', 'eventAction': 'Pixel Depth', 'eventLabel': rounded(scrollDistance), 'eventValue': 1, 'eventNonInteraction': options.nonInteraction});
}

if (options.userTiming && arguments.length > 3) {
standardEventHandler({'event': 'ScrollTiming', 'eventCategory': 'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventTiming': timing});
}

} else {

if (universalGA) {
Expand Down
6 changes: 3 additions & 3 deletions jquery.scrolldepth.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scroll-depth",
"version": "1.1.0",
"version": "1.2.0",
"description": "A Google Analytics plugin for measuring page scrolling.",
"main": "jquery.scrolldepth.js",
"directories": {
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ There's a test HTML file that mocks the Google Analytics functions and writes th
If you have any questions you can find me on Twitter at [@robflaherty](https://twitter.com/robflaherty). If you need help fixing something, **please provide a URL**.

## Changelog
1.2 (7/3/20): Fixed missing gtag.js support for pixel depth and timing events

1.1 (6/26/20): Added gtag.js support

1.0 (12/8/16): Added support for customer tracker name and custom dataLayer name.
Expand Down
20 changes: 13 additions & 7 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,25 @@ <h1>jQuery Scroll Depth Test Page</h1>
log("ga(" + args.join(',') + ");");
};

var gtag = function(params) {
var args = Array.prototype.slice.call(arguments, 1);
log("gtag(" + args.join(',') + ");");
};

_gaq = undefined;
dataLayer = undefined;
//ga = undefined;
ga = undefined;
//gtag = undefined;

$.scrollDepth({
elements: ['#main'],
userTiming: false,
percentage: false,
pixelDepth: false
userTiming: true,
percentage: true,
pixelDepth: true,
//gtmOverride: true,
//eventHandler: function(data) {
//log(data)
//}
// eventHandler: function(data) {
// log(data)
// }
});
</script>
</body>
Expand Down

0 comments on commit ac54006

Please sign in to comment.