@xylabs/pixel 1.2.5 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/Pixel.js +6 -0
- package/dist/Pixel.js.map +1 -1
- package/dist/UtmFields.js +3 -2
- package/dist/UtmFields.js.map +1 -1
- package/dist/{node-esm/src → esm2017}/Api/Api.d.ts +7 -7
- package/dist/{node-esm/src → esm2017}/Api/UserEvent.d.ts +18 -18
- package/dist/{node-esm/src → esm2017}/Api/UserEventSystem.d.ts +3 -3
- package/dist/esm2017/{src/Api → Api}/index.d.ts +5 -5
- package/dist/esm2017/{src/CommonFields.d.ts → CommonFields.d.ts} +5 -5
- package/dist/{esm5/src → esm2017}/ExIds.d.ts +10 -10
- package/dist/{node-esm/src → esm2017}/FunnelStartedFields.d.ts +5 -5
- package/dist/esm2017/{src/Pixel.d.ts → Pixel.d.ts} +23 -23
- package/dist/{node-esm/src → esm2017}/Referrer.d.ts +13 -13
- package/dist/{esm5/src → esm2017}/TestStartedFields.d.ts +5 -5
- package/dist/esm2017/{src/UniqueUserId.d.ts → UniqueUserId.d.ts} +8 -8
- package/dist/{esm5/src → esm2017}/UserClickFields.d.ts +6 -6
- package/dist/{node-esm/src → esm2017}/UserEventHandler.d.ts +11 -11
- package/dist/{node-esm/src → esm2017}/UtmFields.d.ts +9 -9
- package/dist/esm2017/{src/ViewContentFields.d.ts → ViewContentFields.d.ts} +6 -6
- package/dist/{esm5/src → esm2017}/XyLabsTrackingEventJson.d.ts +19 -19
- package/dist/esm2017/{src/XyUserEventHandler.d.ts → XyUserEventHandler.d.ts} +13 -13
- package/dist/esm2017/getSystemInfo.d.ts +2 -0
- package/dist/esm2017/index.d.ts +14 -1
- package/dist/esm2017/index.js +396 -211
- package/dist/esm2017/index.js.map +1 -1
- package/dist/{esm2017/src → esm5}/Api/Api.d.ts +7 -7
- package/dist/{node/src → esm5}/Api/UserEvent.d.ts +18 -18
- package/dist/esm5/{src/Api → Api}/UserEventSystem.d.ts +3 -3
- package/dist/{node-esm/src → esm5}/Api/index.d.ts +5 -5
- package/dist/{node-esm/src → esm5}/CommonFields.d.ts +5 -5
- package/dist/{node-esm/src → esm5}/ExIds.d.ts +10 -10
- package/dist/{node/src → esm5}/FunnelStartedFields.d.ts +5 -5
- package/dist/esm5/{src/Pixel.d.ts → Pixel.d.ts} +23 -23
- package/dist/{node/src → esm5}/Referrer.d.ts +13 -13
- package/dist/{esm2017/src → esm5}/TestStartedFields.d.ts +5 -5
- package/dist/esm5/{src/UniqueUserId.d.ts → UniqueUserId.d.ts} +8 -8
- package/dist/{node-esm/src → esm5}/UserClickFields.d.ts +6 -6
- package/dist/{node/src → esm5}/UserEventHandler.d.ts +11 -11
- package/dist/{node/src → esm5}/UtmFields.d.ts +9 -9
- package/dist/esm5/{src/ViewContentFields.d.ts → ViewContentFields.d.ts} +6 -6
- package/dist/{esm2017/src → esm5}/XyLabsTrackingEventJson.d.ts +19 -19
- package/dist/esm5/{src/XyUserEventHandler.d.ts → XyUserEventHandler.d.ts} +13 -13
- package/dist/esm5/getSystemInfo.d.ts +2 -0
- package/dist/esm5/index.d.ts +14 -1
- package/dist/esm5/index.js +317 -294
- package/dist/esm5/index.js.map +1 -1
- package/dist/getSystemInfo.d.ts +1 -2
- package/dist/getSystemInfo.js +2 -2
- package/dist/getSystemInfo.js.map +1 -1
- package/dist/node/{src/Api → Api}/Api.d.ts +7 -7
- package/dist/{esm5/src → node}/Api/UserEvent.d.ts +18 -18
- package/dist/{esm2017/src → node}/Api/UserEventSystem.d.ts +3 -3
- package/dist/node/{src/Api → Api}/index.d.ts +5 -5
- package/dist/node/{src/CommonFields.d.ts → CommonFields.d.ts} +5 -5
- package/dist/node/{src/ExIds.d.ts → ExIds.d.ts} +10 -10
- package/dist/{esm2017/src → node}/FunnelStartedFields.d.ts +5 -5
- package/dist/node/{src/Pixel.d.ts → Pixel.d.ts} +23 -23
- package/dist/{esm5/src → node}/Referrer.d.ts +13 -13
- package/dist/node/{src/TestStartedFields.d.ts → TestStartedFields.d.ts} +5 -5
- package/dist/node/{src/UniqueUserId.d.ts → UniqueUserId.d.ts} +8 -8
- package/dist/node/{src/UserClickFields.d.ts → UserClickFields.d.ts} +6 -6
- package/dist/{esm2017/src → node}/UserEventHandler.d.ts +11 -11
- package/dist/{esm5/src → node}/UtmFields.d.ts +9 -9
- package/dist/node/{src/ViewContentFields.d.ts → ViewContentFields.d.ts} +6 -6
- package/dist/node/{src/XyLabsTrackingEventJson.d.ts → XyLabsTrackingEventJson.d.ts} +19 -19
- package/dist/node/{src/XyUserEventHandler.d.ts → XyUserEventHandler.d.ts} +13 -13
- package/dist/node/getSystemInfo.d.ts +2 -0
- package/dist/node/index.d.ts +14 -1
- package/dist/node/index.js +317 -295
- package/dist/node/index.js.map +1 -1
- package/dist/{esm5/src → node-esm}/Api/Api.d.ts +7 -7
- package/dist/{esm2017/src → node-esm}/Api/UserEvent.d.ts +18 -18
- package/dist/{node/src → node-esm}/Api/UserEventSystem.d.ts +3 -3
- package/dist/{esm5/src → node-esm}/Api/index.d.ts +5 -5
- package/dist/{esm5/src → node-esm}/CommonFields.d.ts +5 -5
- package/dist/{esm2017/src → node-esm}/ExIds.d.ts +10 -10
- package/dist/{esm5/src → node-esm}/FunnelStartedFields.d.ts +5 -5
- package/dist/node-esm/{src/Pixel.d.ts → Pixel.d.ts} +23 -23
- package/dist/{esm2017/src → node-esm}/Referrer.d.ts +13 -13
- package/dist/node-esm/{src/TestStartedFields.d.ts → TestStartedFields.d.ts} +5 -5
- package/dist/node-esm/{src/UniqueUserId.d.ts → UniqueUserId.d.ts} +8 -8
- package/dist/{esm2017/src → node-esm}/UserClickFields.d.ts +6 -6
- package/dist/{esm5/src → node-esm}/UserEventHandler.d.ts +11 -11
- package/dist/{esm2017/src → node-esm}/UtmFields.d.ts +9 -9
- package/dist/node-esm/{src/ViewContentFields.d.ts → ViewContentFields.d.ts} +6 -6
- package/dist/node-esm/{src/XyLabsTrackingEventJson.d.ts → XyLabsTrackingEventJson.d.ts} +19 -19
- package/dist/node-esm/{src/XyUserEventHandler.d.ts → XyUserEventHandler.d.ts} +13 -13
- package/dist/node-esm/getSystemInfo.d.ts +2 -0
- package/dist/node-esm/index.d.ts +14 -1
- package/dist/node-esm/index.js +396 -211
- package/dist/node-esm/index.js.map +1 -1
- package/jest.config.cjs +22 -3
- package/package.json +20 -27
- package/rollup.config.js +2 -120
- package/src/Pixel.spec.ts +2 -1
- package/src/Pixel.ts +7 -0
- package/src/getSystemInfo.ts +2 -2
- package/dist/esm2017/index.node.d.ts +0 -1
- package/dist/esm2017/src/Pixel.spec.d.ts +0 -1
- package/dist/esm2017/src/getSystemInfo.d.ts +0 -3
- package/dist/esm2017/src/index.d.ts +0 -14
- package/dist/esm5/index.node.d.ts +0 -1
- package/dist/esm5/src/Pixel.spec.d.ts +0 -1
- package/dist/esm5/src/getSystemInfo.d.ts +0 -3
- package/dist/esm5/src/index.d.ts +0 -14
- package/dist/node/index.node.d.ts +0 -1
- package/dist/node/src/Pixel.spec.d.ts +0 -1
- package/dist/node/src/getSystemInfo.d.ts +0 -3
- package/dist/node/src/index.d.ts +0 -14
- package/dist/node-esm/index.node.d.ts +0 -1
- package/dist/node-esm/src/Pixel.spec.d.ts +0 -1
- package/dist/node-esm/src/getSystemInfo.d.ts +0 -3
- package/dist/node-esm/src/index.d.ts +0 -14
- package/index.node.ts +0 -1
- package/index.ts +0 -1
package/dist/esm2017/index.js
CHANGED
|
@@ -5,232 +5,417 @@ import { Mutex } from 'async-mutex';
|
|
|
5
5
|
import Cookies from 'js-cookie';
|
|
6
6
|
import md5 from 'md5';
|
|
7
7
|
import axios from 'axios';
|
|
8
|
-
import
|
|
8
|
+
import { parse } from 'bowser';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _a, _b;
|
|
13
|
-
this.session = (_a = this.getFromSession()) !== null && _a !== void 0 ? _a : document.referrer;
|
|
14
|
-
sessionStorage.setItem(Referrer.storageId, this.session);
|
|
15
|
-
this.local = (_b = this.getFromLocal()) !== null && _b !== void 0 ? _b : document.referrer;
|
|
16
|
-
window.localStorage.setItem(Referrer.storageId, this.local);
|
|
17
|
-
}
|
|
18
|
-
getFromLocal() {
|
|
19
|
-
|
|
20
|
-
if (value && value.length > 0) {
|
|
21
|
-
return value;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
getFromSession() {
|
|
25
|
-
|
|
26
|
-
if (value && value.length > 0) {
|
|
27
|
-
return value;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
toJson() {
|
|
31
|
-
if ((this.local && this.local.length > 0) || (this.session && this.session.length > 0)) {
|
|
32
|
-
return {
|
|
33
|
-
local: this.local,
|
|
34
|
-
session: this.session,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
Referrer
|
|
10
|
+
var Referrer = /** @class */ (function () {
|
|
11
|
+
function Referrer() {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
this.session = (_a = this.getFromSession()) !== null && _a !== void 0 ? _a : document.referrer;
|
|
14
|
+
sessionStorage.setItem(Referrer.storageId, this.session);
|
|
15
|
+
this.local = (_b = this.getFromLocal()) !== null && _b !== void 0 ? _b : document.referrer;
|
|
16
|
+
window.localStorage.setItem(Referrer.storageId, this.local);
|
|
17
|
+
}
|
|
18
|
+
Referrer.prototype.getFromLocal = function () {
|
|
19
|
+
var value = window.localStorage.getItem(Referrer.storageId);
|
|
20
|
+
if (value && value.length > 0) {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
Referrer.prototype.getFromSession = function () {
|
|
25
|
+
var value = sessionStorage.getItem(Referrer.storageId);
|
|
26
|
+
if (value && value.length > 0) {
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
Referrer.prototype.toJson = function () {
|
|
31
|
+
if ((this.local && this.local.length > 0) || (this.session && this.session.length > 0)) {
|
|
32
|
+
return {
|
|
33
|
+
local: this.local,
|
|
34
|
+
session: this.session,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Referrer.storageId = '_coin_referrer';
|
|
39
|
+
return Referrer;
|
|
40
|
+
}());
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var _a;
|
|
44
|
-
this.id = (_a = window.localStorage.getItem(UniqueUserId.localStorageId)) !== null && _a !== void 0 ? _a : this.generateId();
|
|
45
|
-
window.localStorage.setItem(UniqueUserId.localStorageId, this.id);
|
|
46
|
-
}
|
|
47
|
-
generateId() {
|
|
48
|
-
return randomBytes(16).toString('base64');
|
|
49
|
-
}
|
|
50
|
-
toString() {
|
|
51
|
-
return this.id;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
UniqueUserId
|
|
42
|
+
var UniqueUserId = /** @class */ (function () {
|
|
43
|
+
function UniqueUserId() {
|
|
44
|
+
var _a;
|
|
45
|
+
this.id = (_a = window.localStorage.getItem(UniqueUserId.localStorageId)) !== null && _a !== void 0 ? _a : this.generateId();
|
|
46
|
+
window.localStorage.setItem(UniqueUserId.localStorageId, this.id);
|
|
47
|
+
}
|
|
48
|
+
UniqueUserId.prototype.generateId = function () {
|
|
49
|
+
return randomBytes(16).toString('base64');
|
|
50
|
+
};
|
|
51
|
+
UniqueUserId.prototype.toString = function () {
|
|
52
|
+
return this.id;
|
|
53
|
+
};
|
|
54
|
+
UniqueUserId.localStorageId = '_coin_cid';
|
|
55
|
+
return UniqueUserId;
|
|
56
|
+
}());
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
var UserEventHandler = /** @class */ (function () {
|
|
59
|
+
function UserEventHandler() {
|
|
60
|
+
}
|
|
61
|
+
return UserEventHandler;
|
|
62
|
+
}());
|
|
58
63
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
64
|
+
/*! *****************************************************************************
|
|
65
|
+
Copyright (c) Microsoft Corporation.
|
|
66
|
+
|
|
67
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
68
|
+
purpose with or without fee is hereby granted.
|
|
69
|
+
|
|
70
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
71
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
72
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
73
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
74
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
75
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
76
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
77
|
+
***************************************************************************** */
|
|
78
|
+
/* global Reflect, Promise */
|
|
79
|
+
|
|
80
|
+
var extendStatics = function(d, b) {
|
|
81
|
+
extendStatics = Object.setPrototypeOf ||
|
|
82
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
83
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
84
|
+
return extendStatics(d, b);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
function __extends(d, b) {
|
|
88
|
+
if (typeof b !== "function" && b !== null)
|
|
89
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
90
|
+
extendStatics(d, b);
|
|
91
|
+
function __() { this.constructor = d; }
|
|
92
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
var __assign = function() {
|
|
96
|
+
__assign = Object.assign || function __assign(t) {
|
|
97
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
98
|
+
s = arguments[i];
|
|
99
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
86
100
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
101
|
+
return t;
|
|
102
|
+
};
|
|
103
|
+
return __assign.apply(this, arguments);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
107
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
108
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
109
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
110
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
111
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
112
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function __generator(thisArg, body) {
|
|
117
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
118
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
119
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
120
|
+
function step(op) {
|
|
121
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
122
|
+
while (_) try {
|
|
123
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
124
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
125
|
+
switch (op[0]) {
|
|
126
|
+
case 0: case 1: t = op; break;
|
|
127
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
128
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
129
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
130
|
+
default:
|
|
131
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
132
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
133
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
134
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
135
|
+
if (t[2]) _.ops.pop();
|
|
136
|
+
_.trys.pop(); continue;
|
|
97
137
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
toString() {
|
|
102
|
-
return JSON.stringify(this.fields);
|
|
138
|
+
op = body.call(thisArg, _);
|
|
139
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
140
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
103
141
|
}
|
|
104
142
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
class PixelApi {
|
|
113
|
-
/* baseUri can either be a preset (prod, beta, local), or a specific uri */
|
|
114
|
-
constructor(baseUri = 'prod') {
|
|
115
|
-
this.endPoint = apiBaseUri[baseUri] ? `${apiBaseUri[baseUri]}/t/event/queue` : baseUri;
|
|
143
|
+
|
|
144
|
+
function __read(o, n) {
|
|
145
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
146
|
+
if (!m) return o;
|
|
147
|
+
var i = m.call(o), r, ar = [], e;
|
|
148
|
+
try {
|
|
149
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
116
150
|
}
|
|
117
|
-
|
|
118
|
-
|
|
151
|
+
catch (error) { e = { error: error }; }
|
|
152
|
+
finally {
|
|
153
|
+
try {
|
|
154
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
155
|
+
}
|
|
156
|
+
finally { if (e) throw e.error; }
|
|
119
157
|
}
|
|
158
|
+
return ar;
|
|
120
159
|
}
|
|
121
160
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
161
|
+
var UtmFields = /** @class */ (function () {
|
|
162
|
+
function UtmFields() {
|
|
163
|
+
var _a;
|
|
164
|
+
this.fields = [];
|
|
165
|
+
this.getUtmRecord = function () {
|
|
166
|
+
var _a, _b;
|
|
167
|
+
var record = {};
|
|
168
|
+
var parsedQueryString = (_b = (_a = document.location.search.split('?')[1]) === null || _a === void 0 ? void 0 : _a.split('&')) !== null && _b !== void 0 ? _b : [];
|
|
169
|
+
parsedQueryString.map(function (item) {
|
|
170
|
+
var _a = __read(item.split('='), 2), fullKey = _a[0], value = _a[1];
|
|
171
|
+
var _b = __read(fullKey.split('_'), 2), keyCategory = _b[0], keyName = _b[1];
|
|
172
|
+
if (keyCategory === 'utm') {
|
|
173
|
+
record[keyName] = value;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
return Object.keys(record).length > 0 ? record : null;
|
|
177
|
+
};
|
|
178
|
+
var storedString = (_a = window.localStorage.getItem(UtmFields.localStorageId)) !== null && _a !== void 0 ? _a : '[]';
|
|
179
|
+
try {
|
|
180
|
+
this.fields = JSON.parse(storedString);
|
|
181
|
+
}
|
|
182
|
+
catch (_b) {
|
|
183
|
+
this.fields = [];
|
|
184
|
+
}
|
|
185
|
+
//this clears the old object version if needed
|
|
186
|
+
if (!Array.isArray(this.fields)) {
|
|
187
|
+
this.fields = [];
|
|
188
|
+
}
|
|
189
|
+
this.update();
|
|
190
|
+
window.localStorage.setItem(UtmFields.localStorageId, JSON.stringify(this.fields));
|
|
191
|
+
}
|
|
192
|
+
//check the query string and if there an new/updated utm values, add them to the fields
|
|
193
|
+
UtmFields.prototype.update = function () {
|
|
194
|
+
var _a;
|
|
195
|
+
var record = this.getUtmRecord();
|
|
196
|
+
if (record) {
|
|
197
|
+
if (!isEqual(this.fields[this.fields.length - 1], record)) {
|
|
198
|
+
this.fields.push(record);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return (_a = this.fields) !== null && _a !== void 0 ? _a : undefined;
|
|
202
|
+
};
|
|
203
|
+
UtmFields.prototype.toString = function () {
|
|
204
|
+
return JSON.stringify(this.fields);
|
|
205
|
+
};
|
|
206
|
+
UtmFields.localStorageId = '_coin_utm';
|
|
207
|
+
return UtmFields;
|
|
208
|
+
}());
|
|
209
|
+
|
|
210
|
+
var apiBaseUri = {
|
|
211
|
+
beta: 'https://pixel.xylabs.com',
|
|
212
|
+
local: 'http://localhost:3030',
|
|
213
|
+
prod: 'https://pixel.xylabs.com',
|
|
131
214
|
};
|
|
215
|
+
var PixelApi = /** @class */ (function () {
|
|
216
|
+
/* baseUri can either be a preset (prod, beta, local), or a specific uri */
|
|
217
|
+
function PixelApi(baseUri) {
|
|
218
|
+
if (baseUri === void 0) { baseUri = 'prod'; }
|
|
219
|
+
this.endPoint = apiBaseUri[baseUri] ? "".concat(apiBaseUri[baseUri], "/t/event/queue") : baseUri;
|
|
220
|
+
}
|
|
221
|
+
PixelApi.prototype.trackEvents = function (events) {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
223
|
+
return __generator(this, function (_a) {
|
|
224
|
+
switch (_a.label) {
|
|
225
|
+
case 0: return [4 /*yield*/, axios.post(this.endPoint, events)];
|
|
226
|
+
case 1: return [2 /*return*/, (_a.sent()).data];
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
return PixelApi;
|
|
232
|
+
}());
|
|
132
233
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
updateFbId() {
|
|
145
|
-
var _a;
|
|
146
|
-
this.exids = Object.assign({
|
|
147
|
-
fbc: Cookies.get('_fbc'),
|
|
148
|
-
fbp: Cookies.get('_fbp'),
|
|
149
|
-
ga: Cookies.get('_ga'),
|
|
150
|
-
gclid: Cookies.get('_gclid'),
|
|
151
|
-
rdt_uid: Cookies.get('rdt_uid'),
|
|
152
|
-
scid: Cookies.get('_scid'),
|
|
153
|
-
tt_sessionId: (_a = sessionStorage.getItem('tt_sessionId')) !== null && _a !== void 0 ? _a : undefined,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
async tryFlushQueue() {
|
|
157
|
-
await this.queueMutex.runExclusive(async () => {
|
|
158
|
-
if (this.queue.length === 0)
|
|
159
|
-
return;
|
|
160
|
-
const api = XyPixel.api;
|
|
161
|
-
if (api) {
|
|
162
|
-
const events = this.queue;
|
|
163
|
-
this.queue = [];
|
|
164
|
-
try {
|
|
165
|
-
await api.trackEvents(events);
|
|
166
|
-
}
|
|
167
|
-
catch (ex) {
|
|
168
|
-
if (events) {
|
|
169
|
-
//put it back since it failed
|
|
170
|
-
this.queue = this.queue.concat(events);
|
|
171
|
-
}
|
|
172
|
-
console.error(ex);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
async send(event, fields) {
|
|
178
|
-
var _a;
|
|
179
|
-
this.updateFbId();
|
|
180
|
-
const utm = XyPixel.utmFields().update();
|
|
181
|
-
const referrer = new Referrer();
|
|
182
|
-
this.queue.push(Object.assign({
|
|
183
|
-
cid: this.cid,
|
|
184
|
-
create_time: Date.now(),
|
|
185
|
-
email_hash: (_a = this.email_hash) !== null && _a !== void 0 ? _a : undefined,
|
|
186
|
-
event,
|
|
187
|
-
exids: this.exids,
|
|
188
|
-
fields,
|
|
189
|
-
host: document.location.host,
|
|
190
|
-
pathname: document.location.pathname,
|
|
191
|
-
pixel: this.pixelId,
|
|
192
|
-
referrer: referrer.toJson(),
|
|
193
|
-
system: getSystemInfo(),
|
|
194
|
-
utm,
|
|
195
|
-
}));
|
|
196
|
-
await this.tryFlushQueue();
|
|
197
|
-
}
|
|
198
|
-
static get instance() {
|
|
199
|
-
return assertEx(this._instance, 'XyPixel uninitialized');
|
|
200
|
-
}
|
|
201
|
-
static init(pixelId) {
|
|
202
|
-
this._instance = new XyPixel(pixelId);
|
|
203
|
-
return this._instance;
|
|
204
|
-
}
|
|
205
|
-
static selectApi(api) {
|
|
206
|
-
this.api = api;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
XyPixel.utmFields = () => {
|
|
210
|
-
if (XyPixel.utmFieldsObj === undefined) {
|
|
211
|
-
XyPixel.utmFieldsObj = new UtmFields();
|
|
212
|
-
}
|
|
213
|
-
return XyPixel.utmFieldsObj;
|
|
214
|
-
};
|
|
215
|
-
XyPixel.api = new PixelApi();
|
|
234
|
+
var systemInfo = undefined;
|
|
235
|
+
var getSystemInfo = function () {
|
|
236
|
+
try {
|
|
237
|
+
systemInfo = systemInfo || parse(window.navigator.userAgent);
|
|
238
|
+
}
|
|
239
|
+
catch (ex) {
|
|
240
|
+
console.log("getSystemInfo Error: ".concat(ex));
|
|
241
|
+
}
|
|
242
|
+
return systemInfo;
|
|
243
|
+
};
|
|
216
244
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
|
|
245
|
+
var emailHashLocalStorageName = 'xy_email_hash';
|
|
246
|
+
var XyPixel = /** @class */ (function () {
|
|
247
|
+
function XyPixel(pixelId) {
|
|
248
|
+
this.queue = [];
|
|
249
|
+
this.cid = new UniqueUserId().id;
|
|
250
|
+
this.queueMutex = new Mutex();
|
|
251
|
+
this.pixelId = pixelId;
|
|
252
|
+
this.email_hash = localStorage.getItem(emailHashLocalStorageName);
|
|
253
|
+
}
|
|
254
|
+
XyPixel.prototype.identify = function (email) {
|
|
255
|
+
this.email = email;
|
|
256
|
+
this.email_hash = email ? md5(email) : undefined;
|
|
257
|
+
if (this.email_hash) {
|
|
258
|
+
localStorage.setItem(emailHashLocalStorageName, this.email_hash);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
XyPixel.prototype.updateFbId = function () {
|
|
262
|
+
var _a;
|
|
263
|
+
this.exids = __assign({
|
|
264
|
+
fbc: Cookies.get('_fbc'),
|
|
265
|
+
fbp: Cookies.get('_fbp'),
|
|
266
|
+
ga: Cookies.get('_ga'),
|
|
267
|
+
gclid: Cookies.get('_gclid'),
|
|
268
|
+
rdt_uid: Cookies.get('rdt_uid'),
|
|
269
|
+
scid: Cookies.get('_scid'),
|
|
270
|
+
tt_sessionId: (_a = sessionStorage.getItem('tt_sessionId')) !== null && _a !== void 0 ? _a : undefined,
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
XyPixel.prototype.tryFlushQueue = function () {
|
|
274
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
275
|
+
var _this = this;
|
|
276
|
+
return __generator(this, function (_a) {
|
|
277
|
+
switch (_a.label) {
|
|
278
|
+
case 0: return [4 /*yield*/, this.queueMutex.runExclusive(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
279
|
+
var api, events, ex_1;
|
|
280
|
+
return __generator(this, function (_a) {
|
|
281
|
+
switch (_a.label) {
|
|
282
|
+
case 0:
|
|
283
|
+
if (this.queue.length === 0)
|
|
284
|
+
return [2 /*return*/];
|
|
285
|
+
api = XyPixel.api;
|
|
286
|
+
if (!api) return [3 /*break*/, 4];
|
|
287
|
+
events = this.queue;
|
|
288
|
+
this.queue = [];
|
|
289
|
+
_a.label = 1;
|
|
290
|
+
case 1:
|
|
291
|
+
_a.trys.push([1, 3, , 4]);
|
|
292
|
+
return [4 /*yield*/, api.trackEvents(events)];
|
|
293
|
+
case 2:
|
|
294
|
+
_a.sent();
|
|
295
|
+
return [3 /*break*/, 4];
|
|
296
|
+
case 3:
|
|
297
|
+
ex_1 = _a.sent();
|
|
298
|
+
if (events) {
|
|
299
|
+
//put it back since it failed
|
|
300
|
+
this.queue = this.queue.concat(events);
|
|
301
|
+
}
|
|
302
|
+
console.error(ex_1);
|
|
303
|
+
return [3 /*break*/, 4];
|
|
304
|
+
case 4: return [2 /*return*/];
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}); })];
|
|
308
|
+
case 1:
|
|
309
|
+
_a.sent();
|
|
310
|
+
return [2 /*return*/];
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
};
|
|
315
|
+
XyPixel.prototype.send = function (event, fields) {
|
|
316
|
+
var _a;
|
|
317
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
318
|
+
var utm, referrer;
|
|
319
|
+
return __generator(this, function (_b) {
|
|
320
|
+
switch (_b.label) {
|
|
321
|
+
case 0:
|
|
322
|
+
this.updateFbId();
|
|
323
|
+
utm = XyPixel.utmFields().update();
|
|
324
|
+
referrer = new Referrer();
|
|
325
|
+
this.queue.push(__assign({
|
|
326
|
+
cid: this.cid,
|
|
327
|
+
create_time: Date.now(),
|
|
328
|
+
email_hash: (_a = this.email_hash) !== null && _a !== void 0 ? _a : undefined,
|
|
329
|
+
event: event,
|
|
330
|
+
exids: this.exids,
|
|
331
|
+
fields: fields,
|
|
332
|
+
host: document.location.host,
|
|
333
|
+
pathname: document.location.pathname,
|
|
334
|
+
pixel: this.pixelId,
|
|
335
|
+
referrer: referrer.toJson(),
|
|
336
|
+
system: getSystemInfo(),
|
|
337
|
+
utm: utm,
|
|
338
|
+
}));
|
|
339
|
+
console.log("Queue: ".concat(JSON.stringify(this.queue, null, 2)));
|
|
340
|
+
return [4 /*yield*/, this.tryFlushQueue()];
|
|
341
|
+
case 1:
|
|
342
|
+
_b.sent();
|
|
343
|
+
return [2 /*return*/];
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
};
|
|
348
|
+
Object.defineProperty(XyPixel, "instance", {
|
|
349
|
+
get: function () {
|
|
350
|
+
return assertEx(this._instance, 'XyPixel uninitialized');
|
|
351
|
+
},
|
|
352
|
+
enumerable: false,
|
|
353
|
+
configurable: true
|
|
354
|
+
});
|
|
355
|
+
XyPixel.init = function (pixelId) {
|
|
356
|
+
this._instance = new XyPixel(pixelId);
|
|
357
|
+
return this._instance;
|
|
358
|
+
};
|
|
359
|
+
XyPixel.selectApi = function (api) {
|
|
360
|
+
this.api = api;
|
|
361
|
+
};
|
|
362
|
+
XyPixel.utmFields = function () {
|
|
363
|
+
if (XyPixel.utmFieldsObj === undefined) {
|
|
364
|
+
XyPixel.utmFieldsObj = new UtmFields();
|
|
365
|
+
}
|
|
366
|
+
return XyPixel.utmFieldsObj;
|
|
367
|
+
};
|
|
368
|
+
XyPixel.api = new PixelApi();
|
|
369
|
+
return XyPixel;
|
|
370
|
+
}());
|
|
371
|
+
|
|
372
|
+
var XyUserEventHandler = /** @class */ (function (_super) {
|
|
373
|
+
__extends(XyUserEventHandler, _super);
|
|
374
|
+
function XyUserEventHandler() {
|
|
375
|
+
return _super.call(this) || this;
|
|
376
|
+
}
|
|
377
|
+
XyUserEventHandler.prototype.testStarted = function (fields) {
|
|
378
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
379
|
+
return __generator(this, function (_a) {
|
|
380
|
+
switch (_a.label) {
|
|
381
|
+
case 0: return [4 /*yield*/, XyPixel.instance.send('TestStarted', fields)];
|
|
382
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
XyUserEventHandler.prototype.funnelStarted = function (fields) {
|
|
388
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
389
|
+
return __generator(this, function (_a) {
|
|
390
|
+
switch (_a.label) {
|
|
391
|
+
case 0: return [4 /*yield*/, XyPixel.instance.send('FunnelStarted', fields)];
|
|
392
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
};
|
|
397
|
+
XyUserEventHandler.prototype.viewContent = function (fields) {
|
|
398
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
399
|
+
return __generator(this, function (_a) {
|
|
400
|
+
switch (_a.label) {
|
|
401
|
+
case 0: return [4 /*yield*/, XyPixel.instance.send('ViewContent', fields)];
|
|
402
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
};
|
|
407
|
+
XyUserEventHandler.prototype.userClick = function (fields) {
|
|
408
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
409
|
+
return __generator(this, function (_a) {
|
|
410
|
+
switch (_a.label) {
|
|
411
|
+
case 0: return [4 /*yield*/, XyPixel.instance.send('ViewPage', fields)];
|
|
412
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
};
|
|
417
|
+
return XyUserEventHandler;
|
|
418
|
+
}(UserEventHandler));
|
|
234
419
|
|
|
235
420
|
export { PixelApi, Referrer, UniqueUserId, UserEventHandler, UtmFields, XyPixel, XyUserEventHandler };
|
|
236
421
|
//# sourceMappingURL=index.js.map
|