Skip to content

Commit

Permalink
Merge pull request #41 from antonk777/master
Browse files Browse the repository at this point in the history
Add Google analytics
  • Loading branch information
eransharv authored Jan 11, 2022
2 parents adb8795 + 61dff59 commit cfcd3ce
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
2 changes: 1 addition & 1 deletion native/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"meta": {
"name": "Sample App",
"author": "Overwolf",
"version": "2.0.2",
"version": "2.0.3",
"minimum-overwolf-version": "0.160.0",
"description": "An example app for developers new to Overwolf",
"icon": "icons/IconMouseOver.png",
Expand Down
39 changes: 39 additions & 0 deletions native/scripts/services/google-analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const kGAID = 'UA-144253676-6';

export class GoogleAnalytics {
_loadGALib() {
return new Promise((resolve, reject) => {
const el = document.createElement('script');
el.src = `https://www.google-analytics.com/analytics.js`;
el.async = true;
el.onload = resolve;
el.onerror = reject;
document.body.appendChild(el);
});
}

_createGA() {
window.ga = window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
}

start() {
this._createGA();

const loadPromise = this._loadGALib();

window.ga('create', {
trackingId: kGAID,
cookieDomain: 'none'
});

window.ga('set', 'checkProtocolTask', null);

return loadPromise;
}

ga(...args) {
if (window.ga) {
return window.ga(...args);
}
}
}
13 changes: 9 additions & 4 deletions native/windows/background/background-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { WindowsService } from '../../scripts/services/windows-service.js';
import { HotkeysService } from '../../scripts/services/hotkeys-service.js';
import { GepService } from '../../scripts/services/gep-service.js';
import { EventBus } from '../../scripts/services/event-bus.js';
import { GoogleAnalytics } from '../../scripts/services/google-analytics.js';
import { kGameClassIds, kGamesFeatures } from '../../scripts/constants/games-features.js';
import { kHotkeyToggle } from '../../scripts/constants/hotkeys-ids.js';

Expand All @@ -14,6 +15,7 @@ export class BackgroundController {
this.runningGameService = new RunningGameService();
this.hotkeysService = new HotkeysService();
this.owEventBus = new EventBus();
this.ga = new GoogleAnalytics();
}

async run() {
Expand All @@ -37,10 +39,13 @@ export class BackgroundController {
}
});

// Listen to changes in windows
overwolf.windows.onStateChanged.addListener(
() => this._onWindowStateChanged()
);
// Listen to changes in window states
overwolf.windows.onStateChanged.addListener(() => {
this._onWindowStateChanged();
});

this.ga.start();
this.ga.ga('send', 'pageview');
}

/**
Expand Down
9 changes: 8 additions & 1 deletion native/windows/sample-app-view.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DragService } from '../scripts/services/drag-service.js';
import { GoogleAnalytics } from '../scripts/services/google-analytics.js';

export class SampleAppView {
constructor() {
Expand All @@ -9,7 +10,10 @@ export class SampleAppView {
this._minimizeButton = document.getElementById('minimizeButton');
this._header = document.getElementsByClassName('app-header')[0];
this._version = document.getElementById('version');
// Inittialize
this._ga = new GoogleAnalytics();
this._dragService = null;

// Initialize
this.init();
}

Expand All @@ -33,5 +37,8 @@ export class SampleAppView {
}
this._version.textContent = `Version ${manifest.meta.version}`;
});

this._ga.start();
this._ga.ga('send', 'pageview');
}
}

0 comments on commit cfcd3ce

Please sign in to comment.