-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogleAnalytics.js
More file actions
37 lines (29 loc) · 931 Bytes
/
GoogleAnalytics.js
File metadata and controls
37 lines (29 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var CLIENT_ID_KEY = "settings:clientId";
var analytics = navigator.analytics;
if (analytics) {
analytics.setTrackingId("UA-45806093-6");
analytics.set(analytics.Fields.CLIENT_ID, getClientId());
analytics.set(analytics.Fields.APP_NAME, "تطبيق أخبار جامعة الملك سعود");
analytics.sendEvent("application", "start");
}
function getClientId() {
var clientId = localStorage.getItem(CLIENT_ID_KEY);
if (clientId == null) {
clientId = generateUUID();
localStorage.setItem(CLIENT_ID_KEY, clientId);
}
return clientId;
}
function generateUUID() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0;
return (c === "x" ? r : r & 0x3 | 0x8).toString(16);
});
}
module.exports = {
sendEvent: function (category, action, label) {
if (analytics) {
analytics.sendEvent(category, action, label);
}
}
};