How to get there: that is the question which is answered in the following gist.
Create new template, so we can hook to Template.googleAnalytics.rendered function. So, when googleAnalytics template is rendered, we can call Google Analytics service.
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
<template name='googleAnalytics'> | |
</template> |
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
<body> | |
{{> googleAnalytics}} | |
</body> |
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
Template.googleAnalytics.rendered = function() { | |
new GA('UA-111111-1'); | |
} | |
GA = function(code) { | |
var _gaq = window._gaq || []; | |
_gaq.push(['_setAccount', code]); | |
_gaq.push(['_trackPageview']); | |
(function() { | |
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | |
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
})(); | |
}; | |
No comments:
Post a Comment