Skip to content

Commit

Permalink
refactor: inline everything!
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Oct 13, 2018
1 parent dc003bc commit b4b86df
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
var KEY = 'ga:user';
var UID = (localStorage[KEY] = localStorage[KEY] || Math.random() + '.' + Math.random());

function GA(ua, opts, toWait) {
export default function (ua, opts, toWait) {
opts = opts || {};
this.args = Object.assign({ tid:ua, cid:UID }, opts);
toWait || this.send('pageview');
}
var args = Object.assign({ tid:ua, cid:UID }, opts);

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() });
var k, str='https://www.google-analytics.com/collect?v=1';
for (k in obj) {
// modified `obj-str` behavior
if (obj[k]) str += ('&' + k + '=' + encodeURIComponent(obj[k]));
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
}
new Image().src = str; // dispatch a GET
};

export default GA;
toWait || send('pageview');

return { args, send };
}

0 comments on commit b4b86df

Please sign in to comment.