Skip to content

Commit

Permalink
Added option to set TrackingID
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Isler committed Aug 2, 2018
1 parent 8070941 commit 5833d82
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ library, it replicates the tracking functionality of Google Analytics.

# Constructor

* `new GAParser([domains], limitRelevant = true)`
* `new GAParser([domains], trackingId = 'UA-XXXYYYZZZ-1', limitRelevant = true)`

Returns a new instance.
`domains` must be an array of all domains you want to include in tracking.
Expand Down Expand Up @@ -54,7 +54,7 @@ Adds a hidden input to the specified form containing a JSON string with parsed i

```
<!-- Add before </body> for all domains you want to include in tracking -->
<script src="https://cdn.jsdelivr.net/gh/spiritix/ga-legacy-cookie-parser@0.2.1/dist/ga-legacy-cookie-parser.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/spiritix/ga-legacy-cookie-parser@0.3.0/dist/ga-legacy-cookie-parser.min.js"></script>
<script>
var parser = new GAParser(['mydomain.com', 'second.com']);
console.log(parser.getInfo()); // Output info to console
Expand Down
2 changes: 1 addition & 1 deletion dist/ga-legacy-cookie-parser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ga-legacy-cookie-parser.pack.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title": "GA Legacy Cookie Parser",
"name": "ga-legacy-cookie-parser-js",
"version": "0.2.1",
"version": "0.3.0",
"author": "Matthias Isler <[email protected]>",
"description": "A workaround for accessing GA data in Universal Analytics environments.",
"keywords": [
Expand Down
12 changes: 7 additions & 5 deletions src/ga-legacy-cookie-parser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* GA Legacy Cookie Parser v0.2.1
* GA Legacy Cookie Parser v0.3.0
*
* A workaround for accessing GA data in Universal Analytics environments.
* https://github.com/spiritix/ga-legacy-cookie-parser
Expand All @@ -18,10 +18,10 @@
return hostname.toLowerCase();
}

function setupAnalytics(hostname) {
function setupAnalytics(trackingId, hostname) {
window._gaq = window._gaq || [];

window._gaq.push(['xxga._setAccount', 'UA-XXXYYYZZZ-1']);
window._gaq.push(['xxga._setAccount', trackingId]);
window._gaq.push(['xxga._setDomainName', hostname]);
window._gaq.push(['xxga._setAllowLinker', true]);
window._gaq.push(['xxga._trackPageview']);
Expand Down Expand Up @@ -183,11 +183,13 @@
document.getElementById(formId).appendChild(element1);
}

var GAParser = function(domains, limitRelevant) {
var GAParser = function(domains, trackingId, limitRelevant) {
trackingId = trackingId || 'UA-XXXYYYZZZ-1';
limitRelevant = limitRelevant || true;

var hostname = getHostname();
setupAnalytics(hostname);

setupAnalytics(trackingId, hostname);
trackLinks(hostname, domains);

this.getInfo = function() {
Expand Down

0 comments on commit 5833d82

Please sign in to comment.