|
64 | 64 |
|
65 | 65 | function sendEvent(action, label, scrollDistance, timing) {
|
66 | 66 |
|
67 |
| - scrollDistance = Math.floor(scrollDistance/250) * 250; |
68 |
| - |
69 | 67 | if (googleTagManager) {
|
70 | 68 |
|
71 | 69 | dataLayer.push({'event': 'ScrollDistance', 'eventCategory': 'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventValue': 1, 'eventNonInteraction': true});
|
72 | 70 |
|
73 | 71 | if (options.pixelDepth && arguments.length > 2 && scrollDistance > lastPixelDepth) {
|
74 | 72 | lastPixelDepth = scrollDistance;
|
75 |
| - dataLayer.push({'event': 'ScrollDistance', 'eventCategory': 'Scroll Depth', 'eventAction': 'Pixel Depth', 'eventLabel': scrollDistance.toString(), 'eventValue': 1, 'eventNonInteraction': true}); |
| 73 | + dataLayer.push({'event': 'ScrollDistance', 'eventCategory': 'Scroll Depth', 'eventAction': 'Pixel Depth', 'eventLabel': rounded(scrollDistance), 'eventValue': 1, 'eventNonInteraction': true}); |
76 | 74 | }
|
77 | 75 |
|
78 | 76 | if (options.userTiming && arguments.length > 3) {
|
|
87 | 85 |
|
88 | 86 | if (options.pixelDepth && arguments.length > 2 && scrollDistance > lastPixelDepth) {
|
89 | 87 | lastPixelDepth = scrollDistance;
|
90 |
| - ga('send', 'event', 'Scroll Depth', 'Pixel Depth', scrollDistance.toString(), 1, {'nonInteraction': 1}); |
| 88 | + ga('send', 'event', 'Scroll Depth', 'Pixel Depth', rounded(scrollDistance), 1, {'nonInteraction': 1}); |
91 | 89 | }
|
92 | 90 |
|
93 | 91 | if (options.userTiming && arguments.length > 3) {
|
|
102 | 100 |
|
103 | 101 | if (options.pixelDepth && arguments.length > 2 && scrollDistance > lastPixelDepth) {
|
104 | 102 | lastPixelDepth = scrollDistance;
|
105 |
| - _gaq.push(['_trackEvent', 'Scroll Depth', 'Pixel Depth', scrollDistance.toString(), 1, true]); |
| 103 | + _gaq.push(['_trackEvent', 'Scroll Depth', 'Pixel Depth', rounded(scrollDistance), 1, true]); |
106 | 104 | }
|
107 | 105 |
|
108 | 106 | if (options.userTiming && arguments.length > 3) {
|
|
146 | 144 | });
|
147 | 145 | }
|
148 | 146 |
|
| 147 | + function rounded(scrollDistance) { |
| 148 | + // Returns String |
| 149 | + return (Math.floor(scrollDistance/250) * 250).toString(); |
| 150 | + } |
| 151 | + |
149 | 152 | /*
|
150 | 153 | * Throttle function borrowed from:
|
151 | 154 | * Underscore.js 1.5.2
|
|
0 commit comments