mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Upgrade to NPM Amplitude package (#10952)
* chore(analytics): upgrade to NPM Amplitude pkg * chore(build): run package-lock on Linux * refactor(analytics): use preferred Amplitude v3+ syntax * refactor(analytics): more v3+ syntax * chore(npm): attempt updating package lock
This commit is contained in:
committed by
Matteo Pagliazzi
parent
c15b55808e
commit
b8aacc03e3
11254
package-lock.json
generated
11254
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -8,6 +8,7 @@
|
|||||||
"accepts": "^1.3.5",
|
"accepts": "^1.3.5",
|
||||||
"amazon-payments": "^0.2.7",
|
"amazon-payments": "^0.2.7",
|
||||||
"amplitude": "^3.5.0",
|
"amplitude": "^3.5.0",
|
||||||
|
"amplitude-js": "^4.6.0-beta.2",
|
||||||
"apidoc": "^0.17.5",
|
"apidoc": "^0.17.5",
|
||||||
"apn": "^2.2.0",
|
"apn": "^2.2.0",
|
||||||
"autoprefixer": "^8.5.0",
|
"autoprefixer": "^8.5.0",
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
import forEach from 'lodash/forEach';
|
||||||
import isEqual from 'lodash/isEqual';
|
import isEqual from 'lodash/isEqual';
|
||||||
import keys from 'lodash/keys';
|
import keys from 'lodash/keys';
|
||||||
import pick from 'lodash/pick';
|
import pick from 'lodash/pick';
|
||||||
import includes from 'lodash/includes';
|
import includes from 'lodash/includes';
|
||||||
import getStore from 'client/store';
|
import getStore from 'client/store';
|
||||||
|
import amplitude from 'amplitude-js';
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
|
||||||
const IS_PRODUCTION = process.env.NODE_ENV === 'production'; // eslint-disable-line no-process-env
|
const IS_PRODUCTION = process.env.NODE_ENV === 'production'; // eslint-disable-line no-process-env
|
||||||
@@ -70,7 +72,7 @@ function _gatherUserStats (properties) {
|
|||||||
export function setUser () {
|
export function setUser () {
|
||||||
const store = getStore();
|
const store = getStore();
|
||||||
const user = store.state.user.data;
|
const user = store.state.user.data;
|
||||||
window.amplitude.setUserId(user._id);
|
amplitude.getInstance().setUserId(user._id);
|
||||||
window.ga('set', {userId: user._id});
|
window.ga('set', {userId: user._id});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +82,7 @@ export function track (properties) {
|
|||||||
if (_doesNotHaveRequiredFields(properties)) return false;
|
if (_doesNotHaveRequiredFields(properties)) return false;
|
||||||
if (_doesNotHaveAllowedHitType(properties)) return false;
|
if (_doesNotHaveAllowedHitType(properties)) return false;
|
||||||
|
|
||||||
window.amplitude.logEvent(properties.eventAction, properties);
|
amplitude.getInstance().logEvent(properties.eventAction, properties);
|
||||||
window.ga('send', properties);
|
window.ga('send', properties);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -92,7 +94,11 @@ export function updateUser (properties) {
|
|||||||
|
|
||||||
_gatherUserStats(properties);
|
_gatherUserStats(properties);
|
||||||
|
|
||||||
window.amplitude.setUserProperties(properties);
|
forEach(properties, (value, key) => {
|
||||||
|
const identify = new amplitude.Identify().set(key, value);
|
||||||
|
amplitude.getInstance().identify(identify);
|
||||||
|
});
|
||||||
|
|
||||||
window.ga('set', properties);
|
window.ga('set', properties);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -103,13 +109,7 @@ export function setup () {
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
|
|
||||||
// Amplitude
|
// Amplitude
|
||||||
var r = window.amplitude || {};
|
amplitude.getInstance().init(AMPLITUDE_KEY);
|
||||||
r._q = [];
|
|
||||||
function a(window) {r[window] = function() {r._q.push([window].concat(Array.prototype.slice.call(arguments, 0)));}}
|
|
||||||
var i = ["init", "logEvent", "logRevenue", "setUserId", "setUserProperties", "setOptOut", "setVersionName", "setDomain", "setDeviceId", "setGlobalUserProperties"];
|
|
||||||
for (var o = 0; o < i.length; o++) {a(i[o])}
|
|
||||||
window.amplitude = r;
|
|
||||||
amplitude.init(AMPLITUDE_KEY);
|
|
||||||
|
|
||||||
// Google Analytics (aka Universal Analytics)
|
// Google Analytics (aka Universal Analytics)
|
||||||
window['GoogleAnalyticsObject'] = 'ga';
|
window['GoogleAnalyticsObject'] = 'ga';
|
||||||
@@ -124,14 +124,7 @@ export function load () {
|
|||||||
// Load real scripts
|
// Load real scripts
|
||||||
if (!IS_PRODUCTION) return;
|
if (!IS_PRODUCTION) return;
|
||||||
|
|
||||||
// Amplitude
|
|
||||||
const amplitudeScript = document.createElement('script');
|
|
||||||
let firstScript = document.getElementsByTagName('script')[0];
|
let firstScript = document.getElementsByTagName('script')[0];
|
||||||
amplitudeScript.type = 'text/javascript';
|
|
||||||
amplitudeScript.async = true;
|
|
||||||
amplitudeScript.src = 'https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-2.2.0-min.gz.js';
|
|
||||||
firstScript.parentNode.insertBefore(amplitudeScript, firstScript);
|
|
||||||
|
|
||||||
// Google Analytics
|
// Google Analytics
|
||||||
const gaScript = document.createElement('script');
|
const gaScript = document.createElement('script');
|
||||||
firstScript = document.getElementsByTagName('script')[0];
|
firstScript = document.getElementsByTagName('script')[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user