Comparing version 3.0.0 to 3.1.0
var KEY = 'ga:user'; | ||
var UID = (localStorage[KEY] = localStorage[KEY] || Math.random() + '.' + Math.random()); | ||
// modified `obj-str` | ||
function encode(obj) { | ||
var k, str='https://www.google-analytics.com/collect?v=1'; | ||
for (k in obj) { | ||
if (obj[k]) { | ||
str += ('&' + k + '=' + encodeURIComponent(obj[k])); | ||
module.exports = function (ua, opts, toWait) { | ||
opts = opts || {}; | ||
var args = Object.assign({ tid:ua, cid:UID }, opts); | ||
function send(type, opts) { | ||
if (type === 'pageview' && !opts) { | ||
opts = { dl:location.href, dt:document.title }; | ||
} | ||
var k, str='https://www.google-analytics.com/collect?v=1'; | ||
var obj = Object.assign({ t:type }, args, opts, { z:Date.now() }); | ||
for (k in obj) { | ||
// modified `obj-str` behavior | ||
if (obj[k]) str += ('&' + k + '=' + encodeURIComponent(obj[k])); | ||
} | ||
new Image().src = str; // dispatch a GET | ||
} | ||
return str; | ||
} | ||
function GA(ua, opts) { | ||
opts = opts || {}; | ||
this.args = Object.assign({ tid:ua, cid:UID }, opts); | ||
this.send('pageview'); | ||
toWait || send('pageview'); | ||
return { args, send }; | ||
} | ||
GA.prototype.send = function (type, opts) { | ||
if (type === 'pageview' && !opts) { | ||
opts = { dl:location.href, dt:document.title }; | ||
} | ||
var obj = Object.assign({ t:type }, this.args, opts, { z:Date.now() }); | ||
new Image().src = encode(obj); // dispatch a GET | ||
}; | ||
module.exports = GA; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.GAnalytics=t()}(this,function(){var e="ga:user",t=localStorage[e]=localStorage[e]||Math.random()+"."+Math.random();function n(e,n){n=n||{},this.args=Object.assign({tid:e,cid:t},n),this.send("pageview")}return n.prototype.send=function(e,t){"pageview"!==e||t||(t={dl:location.href,dt:document.title});var n=Object.assign({t:e},this.args,t,{z:Date.now()});(new Image).src=function(e){var t,n="https://www.google-analytics.com/collect?v=1";for(t in e)e[t]&&(n+="&"+t+"="+encodeURIComponent(e[t]));return n}(n)},n}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.GAnalytics=t()}(this,function(){var e=localStorage["ga:user"]=localStorage["ga:user"]||Math.random()+"."+Math.random();return function(a,t,o){t=t||{};var n=Object.assign({tid:a,cid:e},t);function r(e,a){"pageview"!==e||a||(a={dl:location.href,dt:document.title});var t,o="https://www.google-analytics.com/collect?v=1",r=Object.assign({t:e},n,a,{z:Date.now()});for(t in r)r[t]&&(o+="&"+t+"="+encodeURIComponent(r[t]));(new Image).src=o}return o||r("pageview"),{args:n,send:r}};}); |
{ | ||
"name": "ganalytics", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"umd:name": "GAnalytics", | ||
"repository": "lukeed/ganalytics", | ||
"description": "A tiny (358B) client-side module for tracking with Google Analytics", | ||
"umd:main": "dist/ganalytics.min.js", | ||
"module": "dist/ganalytics.es.js", | ||
"description": "A tiny (323B) client-side module for tracking with Google Analytics", | ||
"unpkg": "dist/ganalytics.min.js", | ||
"module": "dist/ganalytics.mjs", | ||
"main": "dist/ganalytics.js", | ||
@@ -36,7 +36,7 @@ "license": "MIT", | ||
"gzip-size": "^3.0.0", | ||
"mk-dirs": "^1.0.0", | ||
"mocha": "^3.4.2", | ||
"pretty-bytes": "^4.0.2", | ||
"rollup": "^0.49.2", | ||
"uglify-js": "^3.3.5" | ||
"terser": "^3.10.0" | ||
} | ||
} |
# ganalytics [![Build Status](https://travis-ci.org/lukeed/ganalytics.svg?branch=master)](https://travis-ci.org/lukeed/ganalytics) | ||
> A tiny (358B) client-side module for tracking with Google Analytics | ||
> A tiny (323B) client-side module for tracking with Google Analytics | ||
This module exposes three module definitions: | ||
* **ES Module**: `dist/ganalytics.es.js` | ||
* **ES Module**: `dist/ganalytics.mjs` | ||
* **CommonJS**: `dist/ganalytics.js` | ||
@@ -27,2 +27,4 @@ * **UMD**: `dist/ganalytics.min.js` | ||
const ga = new GAnalytics('UA-XXXXXXXX-X', { aid:1 }); | ||
// or | ||
const ga = GAnalytics('UA-XXXXXXXX-X', { aid:1 }); | ||
@@ -38,3 +40,3 @@ ga.send('pageview'); | ||
### GAnalytics(trackerID, options) | ||
### GAnalytics(trackerID, options, toWait) | ||
@@ -77,3 +79,9 @@ #### trackerID | ||
#### toWait | ||
Type: `Boolean`<br> | ||
Default: `false` | ||
When truthy, a `pageview` event **will not** be sent immediately upon initialization. | ||
### ga.send(type, params) | ||
@@ -80,0 +88,0 @@ |
7783
119
40