Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
chore: analytics tracking
Browse files Browse the repository at this point in the history
Used to determine which parts to spend time on. Tracking is done through Google Analytics and is completely anonymous. A unique id is generated the first time you install the plugin, but is in no way coupled to an EA identifier.
  • Loading branch information
Mardaneus86 committed Sep 23, 2018
1 parent 6767329 commit 5207058
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 100 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"func-names": ["error", "never"],
"import/prefer-default-export": "off",
"no-underscore-dangle": "off"
},
"globals": {
"UA_TOKEN": false
}
}
48 changes: 48 additions & 0 deletions app/core/analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import ua from 'universal-analytics';
import uuid from 'uuid';

import { Database } from './db';

class Analytics {
constructor() {
if (this.ua === undefined) {
let id = Database.get('uuid', '');
if (id === '') {
id = uuid.v4();
Database.set('uuid', id);
}

this.ua = ua({
tid: UA_TOKEN,
cid: id,
uid: id,
});
}
}

trackPage(pageId) {
return new Promise((resolve, reject) => {
this.ua.pageview(pageId, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}

trackEvent(category, action, label = null, value = null) {
return new Promise((resolve, reject) => {
this.ua.event(category, action, label, value, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}
}

export default new Analytics();
2 changes: 2 additions & 0 deletions app/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BaseScript } from './base-script';
import { Database } from './db';
import { Queue } from './queue';
import browser from './browser';
import analytics from './analytics';

export {
BaseScript,
Expand All @@ -12,4 +13,5 @@ export {
Settings,
SettingsEntry,
browser,
analytics,
};
3 changes: 3 additions & 0 deletions app/core/settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import EventEmitter from 'event-emitter-es6';

import analytics from './analytics';

export class Settings extends EventEmitter {
constructor() {
super();
Expand Down Expand Up @@ -38,6 +40,7 @@ export class Settings extends EventEmitter {

entries[0].toggle();

analytics.trackEvent('Settings', `Toggle setting ${id}`, entries[0].isActive);
this._emitEvent(entries[0]);
}

Expand Down
3 changes: 2 additions & 1 deletion app/futbin/futbin-player-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ enums
getAppMain
window $ document
*/
import { BaseScript, Database } from '../core';
import { analytics, BaseScript, Database } from '../core';
import { FutbinSettings } from './settings-entry';

export class FutbinPlayerLinks extends BaseScript {
Expand Down Expand Up @@ -62,6 +62,7 @@ export class FutbinPlayerLinks extends BaseScript {
if (btn.data('resource-id') === selectedItem.resourceId) {
if (futbinLink) {
btn.find('.btn-text').html('View on Futbin');
analytics.trackEvent('Futbin', 'Show player on Futbin', btn.data('resource-id'));
window.open(futbinLink);
} else {
btn.find('.btn-text').html('No exact Futbin player found');
Expand Down
3 changes: 2 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'babel-polyfill';

import initSettingsScreen from './settings';

import { Settings, Queue } from './core';
import { analytics, Settings, Queue } from './core';

import { Logger } from '../fut';
/*
Expand Down Expand Up @@ -31,6 +31,7 @@ window.currentPage = '';

FUINavigationController.prototype.didPush = (t) => {
if (t) {
analytics.trackPage(t.className);
window.onPageNavigation.notify(t.className);
window.currentPage = t.className;
}
Expand Down
2 changes: 2 additions & 0 deletions app/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable no-restricted-syntax */

import './index.scss';
import { analytics } from '../core';
import settingsPage from './html/index/settings.html';

const handleFieldChange = (entry, setting, e) => {
Expand Down Expand Up @@ -71,6 +72,7 @@ export default (settings) => {
}

$('.futsettings-toggle').click(() => {
analytics.trackEvent('Settings', 'Toggle settings', $('.futsettings').is(':visible'));
$('.futsettings').toggle();
});
};
Loading

0 comments on commit 5207058

Please sign in to comment.