├── .gitignore ├── .jshintrc ├── Makefile ├── test └── index.html ├── package.json ├── component.json ├── History.md ├── index.js ├── Readme.md └── License.txt /.gitignore: -------------------------------------------------------------------------------- 1 | components 2 | build 3 | node_modules 4 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "undef": true, 3 | "unused": true, 4 | "laxbreak": true, 5 | "browser": true, 6 | "globals": { 7 | "exports": false, 8 | "require": false, 9 | "module": false 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | build: components index.js 3 | @component build --dev 4 | 5 | components: component.json 6 | @component install --dev 7 | 8 | lint: 9 | @jshint index.js 10 | 11 | clean: 12 | rm -fr build components 13 | 14 | .PHONY: clean lint 15 | -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Test | Google Analytics 4 | 5 | 6 | 7 | 11 | 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "democracyos-ga", 3 | "repo": "DemocracyOS/ga", 4 | "description": "Google Analytics tracking snippet", 5 | "version": "1.2.0", 6 | "keywords": [ 7 | "google", "analytics" 8 | ], 9 | "dependencies": { 10 | "dataset": "0.3.1", 11 | "load-script": "1.0.0" 12 | }, 13 | "browser": { "load": "load-script" }, 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /component.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ga", 3 | "repo": "code42day/ga", 4 | "description": "Google Analytics tracking snippet", 5 | "version": "1.2.0", 6 | "keywords": [ 7 | "google", "analytics" 8 | ], 9 | "dependencies": { 10 | "code42day/dataset": "0.3.0", 11 | "code42day/load": "1.0.0" 12 | }, 13 | "license": "MIT", 14 | "scripts": [ 15 | "index.js" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 2 | 1.2.0 / 2014-02-27 3 | ================== 4 | 5 | * update code42day/dataset 0.2 -> 0.3 6 | * update Readme - suggest code42day/ua 7 | 8 | 1.1.0 / 2013-12-09 9 | ================== 10 | 11 | * return truthy value if GA script is loaded 12 | 13 | 1.0.0 / 2013-10-11 14 | ================== 15 | 16 | * use code42day/load to load GA script 17 | * Simplify jshint options 18 | 19 | 0.1.0 / 2013-01-18 20 | ================== 21 | 22 | * Add usage example 23 | * Initial implementation 24 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var dataset = require('dataset'); 2 | var load = require('load'); 3 | 4 | module.exports = analytics; 5 | 6 | function gaScriptUrl() { 7 | return ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + 8 | '.google-analytics.com/ga.js'; 9 | } 10 | 11 | function analytics(propertyId) { 12 | if (!propertyId) { 13 | propertyId = dataset(document.body, 'gaPropertyId'); 14 | if (!propertyId) { 15 | return; 16 | } 17 | } 18 | 19 | var gaq = window._gaq = window._gaq || []; 20 | gaq.push(['_setAccount', propertyId]); 21 | gaq.push(['_trackPageview']); 22 | 23 | return load(gaScriptUrl()); 24 | } 25 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # ga 3 | 4 | Google Analytics tracking snippet 5 | You might want to use [code42day/ua] instead - it supports new Google Universal Analytics snipper. 6 | 7 | ## Installation 8 | 9 | $ component install code42day/ga 10 | 11 | ## API 12 | 13 | Activate Google Analytics on the page and track page 14 | 15 | require('ga')("UA-XXXX-X"); 16 | 17 | Alternatively you can define GA property ID as a data attribute of document body 18 | 19 | 20 | 21 | Check [test/index.html](https://github.com/code42day/ga/blob/master/test/index.html) for example. 22 | 23 | ## License 24 | 25 | MIT 26 | 27 | [code42day/ua]: https://github.com/code42day/ua 28 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 code42day 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | --------------------------------------------------------------------------------