Skip to content

Commit

Permalink
Fixing GTM double firing. Adding build script for min version
Browse files Browse the repository at this point in the history
  • Loading branch information
robflaherty committed Feb 14, 2014
1 parent 3103231 commit 9355d74
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
uglifyjs jquery.scrolldepth.js -c -m --comments -o jquery.scrolldepth.min.js
32 changes: 17 additions & 15 deletions jquery.scrolldepth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*!
* jquery.scrolldepth.js | v0.4
* Copyright (c) 2013 Rob Flaherty (@robflaherty)
* @preserve
* jquery.scrolldepth.js | v0.4.1
* Copyright (c) 2014 Rob Flaherty (@robflaherty)
* Licensed under the MIT and GPL licenses.
*/
;(function ( $, window, document, undefined ) {
Expand Down Expand Up @@ -42,27 +43,28 @@
function sendEvent(action, label, timing) {
if (!options.testing) {

if (typeof(ga) !== "undefined") {
ga('send', 'event', 'Scroll Depth', action, label, 1, {'nonInteraction': 1});
if (typeof(dataLayer) !== "undefined") {
dataLayer.push({'event':'ScrollDistance', 'eventCategory':'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventValue': 1, 'eventNonInteraction': true});

if (arguments.length > 2) {
ga('send', 'timing', 'Scroll Depth', action, timing, label);
dataLayer.push({'event':'ScrollTiming', 'eventCategory':'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventTiming': timing});
}
}
} else {

if (typeof(_gaq) !== "undefined") {
_gaq.push(['_trackEvent', 'Scroll Depth', action, label, 1, true]);
if (typeof(ga) !== "undefined") {
ga('send', 'event', 'Scroll Depth', action, label, 1, {'nonInteraction': 1});

if (arguments.length > 2) {
_gaq.push(['_trackTiming', 'Scroll Depth', action, timing, label, 100]);
if (arguments.length > 2) {
ga('send', 'timing', 'Scroll Depth', action, timing, label);
}
}
}

if (typeof(dataLayer) !== "undefined") {
dataLayer.push({'event':'ScrollDistance', 'eventCategory':'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventValue': 1, 'eventNonInteraction': true});
if (typeof(_gaq) !== "undefined") {
_gaq.push(['_trackEvent', 'Scroll Depth', action, label, 1, true]);

if (arguments.length > 2) {
dataLayer.push({'event':'ScrollTiming', 'eventCategory':'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventTiming': timing});
if (arguments.length > 2) {
_gaq.push(['_trackTiming', 'Scroll Depth', action, timing, label, 100]);
}
}
}

Expand Down
7 changes: 4 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: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ If you have any questions please leave a comment on the [associated blog post](h

## Changelog

0.4.1 (2/13/14): Fixed GTM firing double events

0.4 (12/23/13): Added support for Google Tag Manager

0.3 (11/21/13): Added throttling of scroll event callback for better performance.
Expand Down
2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>jQuery Scroll Depth Test Page</h1>
<footer style="background: #999; height: 200px; display: block;">footer</footer>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="../jquery.scrolldepth.js"></script>
<script src="../jquery.scrolldepth.min.js"></script>
<script>
$.scrollDepth({
testing: true,
Expand Down

0 comments on commit 9355d74

Please sign in to comment.