-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
14 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,22 @@ | ||
var _super = { | ||
route: Router.route | ||
}; | ||
|
||
Router.route = function(name, options) { | ||
options = attachAnalyticsOptions.call(this, options); | ||
return _super.route.call(this, name, options); | ||
}; | ||
|
||
var attachAnalyticsOptions = function(options) { | ||
options = options || {}; | ||
|
||
if (shouldSendVirtualPageview.call(this, options)) { | ||
attachVirtualPageviewSender.call(this, options); | ||
Router.onRun(function () { | ||
if (shouldSendVirtualPageview(Router.options, this.route.options)) { | ||
gtmBulldozer.bulldoze(); | ||
dataLayer.push({ | ||
event: 'VirtualPageview', | ||
virtualPageURL: this.url | ||
}); | ||
} | ||
this.next(); | ||
}); | ||
|
||
return options; | ||
}; | ||
|
||
var shouldSendVirtualPageview = function(options) { | ||
function shouldSendVirtualPageview(routerOptions, routeOptions) { | ||
if (typeof (window.dataLayer) === 'undefined') { | ||
return false; | ||
} | ||
|
||
if (options && typeof options.trackPageView !== 'undefined') { | ||
return !!options.trackPageView; | ||
if (routeOptions && typeof routeOptions.trackPageView !== 'undefined') { | ||
return !!routeOptions.trackPageView; | ||
} | ||
|
||
return !!this.options && !!this.options.trackPageView; | ||
}; | ||
|
||
var attachVirtualPageviewSender = function(options) { | ||
var originalOnRun = options.onRun; | ||
|
||
options.onRun = function() { | ||
gtmBulldozer.bulldoze(); | ||
dataLayer.push({ | ||
event: 'VirtualPageview', | ||
virtualPageURL: arguments[0].url | ||
}); | ||
|
||
return callEventHandlerOrNext.call(this, originalOnRun, arguments); | ||
}; | ||
}; | ||
|
||
var callEventHandlerOrNext = function(handler, args) { | ||
if (handler) { | ||
return handler.apply(this, [].slice.apply(args)); | ||
} else { | ||
this.next(); | ||
} | ||
return !!routerOptions && !!routerOptions.trackPageView; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package.describe({ | ||
name: 'gorillastack:iron-router-gtm', | ||
version: '0.1.2', | ||
version: '0.2.0', | ||
summary: 'Install google tag manager and track pageviews in iron-router', | ||
git: '[email protected]:GorillaStack/meteor-iron-router-gtm.git', | ||
documentation: 'README.md' | ||
|