0.2.4 • Published 10 years ago
inject-ga v0.2.4
Inject Google Analytics tracking code in HTML pages.
Installation:
npm install inject-gaUsage:
inject-ga input.html -c 'UA-66481277-1' [-o output.html] [-h]Pass the -h flag if you want the code to be injected inside the <head> tag.
If no output target is passed it will default to stdout.
Input:
<html>
<body>
<i>am</i>
</body>
</html>Output:
<html>
<body>
<i>am</i>
<script>
!function(G,o,O,g,l,e){G.GoogleAnalyticsObject=O;G[O]||(G[O]=function(){
(G[O].q=G[O].q||[]).push(arguments)});G[O].l=+new Date;l=o.createElement(g);
e=o.getElementsByTagName(g)[0];l.src='//www.google-analytics.com/analytics.js';
e.parentNode.insertBefore(l,e)}(window,document,'ga','script');
ga('create', 'UA-66481277-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>Tests:
npm test