Skip to content

Commit ac54006

Browse files
committed
merging PR #114; version update
1 parent faee09b commit ac54006

File tree

6 files changed

+36
-28
lines changed

6 files changed

+36
-28
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "scroll-depth",
33
"main": "jquery.scrolldepth.js",
4-
"version": "1.1.0",
4+
"version": "1.2.0",
55
"homepage": "http://scrolldepth.parsnip.io",
66
"authors": [
77
"Rob Flaherty"

jquery.scrolldepth.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* @preserve
3-
* jquery.scrolldepth.js | v1.0
4-
* Copyright (c) 2016 Rob Flaherty (@robflaherty)
3+
* jquery.scrolldepth.js | v1.2.0
4+
* Copyright (c) 2020 Rob Flaherty (@robflaherty)
55
* Licensed under the MIT and GPL licenses.
66
*/
77

@@ -102,7 +102,20 @@
102102

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

105-
if (globalSiteTag) {
105+
if (standardEventHandler) {
106+
107+
standardEventHandler({'event': 'ScrollDistance', 'eventCategory': 'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventValue': 1, 'eventNonInteraction': options.nonInteraction});
108+
109+
if (options.pixelDepth && arguments.length > 2 && scrollDistance > lastPixelDepth) {
110+
lastPixelDepth = scrollDistance;
111+
standardEventHandler({'event': 'ScrollDistance', 'eventCategory': 'Scroll Depth', 'eventAction': 'Pixel Depth', 'eventLabel': rounded(scrollDistance), 'eventValue': 1, 'eventNonInteraction': options.nonInteraction});
112+
}
113+
114+
if (options.userTiming && arguments.length > 3) {
115+
standardEventHandler({'event': 'ScrollTiming', 'eventCategory': 'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventTiming': timing});
116+
}
117+
118+
} else if (globalSiteTag) {
106119

107120
gtag('event', action, {
108121
'event_category': 'Scroll Depth',
@@ -130,19 +143,6 @@
130143
});
131144
}
132145

133-
} else if (standardEventHandler) {
134-
135-
standardEventHandler({'event': 'ScrollDistance', 'eventCategory': 'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventValue': 1, 'eventNonInteraction': options.nonInteraction});
136-
137-
if (options.pixelDepth && arguments.length > 2 && scrollDistance > lastPixelDepth) {
138-
lastPixelDepth = scrollDistance;
139-
standardEventHandler({'event': 'ScrollDistance', 'eventCategory': 'Scroll Depth', 'eventAction': 'Pixel Depth', 'eventLabel': rounded(scrollDistance), 'eventValue': 1, 'eventNonInteraction': options.nonInteraction});
140-
}
141-
142-
if (options.userTiming && arguments.length > 3) {
143-
standardEventHandler({'event': 'ScrollTiming', 'eventCategory': 'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventTiming': timing});
144-
}
145-
146146
} else {
147147

148148
if (universalGA) {

jquery.scrolldepth.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scroll-depth",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "A Google Analytics plugin for measuring page scrolling.",
55
"main": "jquery.scrolldepth.js",
66
"directories": {

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ There's a test HTML file that mocks the Google Analytics functions and writes th
1717
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**.
1818

1919
## Changelog
20+
1.2 (7/3/20): Fixed missing gtag.js support for pixel depth and timing events
21+
2022
1.1 (6/26/20): Added gtag.js support
2123

2224
1.0 (12/8/16): Added support for customer tracker name and custom dataLayer name.

test/index.html

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,25 @@ <h1>jQuery Scroll Depth Test Page</h1>
3737
log("ga(" + args.join(',') + ");");
3838
};
3939

40+
var gtag = function(params) {
41+
var args = Array.prototype.slice.call(arguments, 1);
42+
log("gtag(" + args.join(',') + ");");
43+
};
44+
4045
_gaq = undefined;
4146
dataLayer = undefined;
42-
//ga = undefined;
47+
ga = undefined;
48+
//gtag = undefined;
4349

4450
$.scrollDepth({
4551
elements: ['#main'],
46-
userTiming: false,
47-
percentage: false,
48-
pixelDepth: false
52+
userTiming: true,
53+
percentage: true,
54+
pixelDepth: true,
4955
//gtmOverride: true,
50-
//eventHandler: function(data) {
51-
//log(data)
52-
//}
56+
// eventHandler: function(data) {
57+
// log(data)
58+
// }
5359
});
5460
</script>
5561
</body>

0 commit comments

Comments
 (0)