-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
17 additions
and
16 deletions.
There are no files selected for viewing
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
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 }; | ||
} |