@wscsports/blaze-web-sdk 0.1.11 → 0.1.13

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.
@@ -1,38 +0,0 @@
1
- {
2
- "name": "@wscsports/blaze-web-sdk",
3
- "version": "0.1.11",
4
- "main": "publish/index",
5
- "types": "publish/index",
6
- "files": [
7
- "publish/*"
8
- ],
9
- "scripts": {
10
- "start:dev": "webpack --config webpack.config.dev.js && webpack-dev-server --config webpack.config.dev",
11
- "build:dev": "webpack --config webpack.config.dev.js",
12
- "build:prod": "webpack --config webpack.config.prod.js",
13
- "publish:npm": "npm publish --access public --tag latest"
14
- },
15
- "devDependencies": {
16
- "@types/animejs": "^3.1.7",
17
- "@types/hammerjs": "^2.0.41",
18
- "@types/lodash": "^4.14.195",
19
- "@types/ua-parser-js": "^0.7.36",
20
- "css-loader": "^6.8.1",
21
- "html-webpack-plugin": "^5.5.3",
22
- "javascript-obfuscator": "^4.0.2",
23
- "style-loader": "^3.3.3",
24
- "ts-loader": "^9.4.4",
25
- "typescript": "^5.1.6",
26
- "typescript-declaration-webpack-plugin": "^0.3.0",
27
- "webpack": "^5.88.1",
28
- "webpack-cli": "^5.1.4",
29
- "webpack-dev-server": "^4.15.1",
30
- "webpack-obfuscator": "^3.5.1"
31
- },
32
- "dependencies": {
33
- "animejs": "^3.2.1",
34
- "hammerjs": "^2.0.8",
35
- "lodash": "^4.17.21",
36
- "ua-parser-js": "^1.0.35"
37
- }
38
- }
@@ -1,216 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.WidgetEvent = exports.StoryEvent = exports.AnalyticsEvent = exports.ReferringEventInfo = exports.Category = exports.AnalyticsService = exports.SessionAction = exports.AdAction = void 0;
16
- const ua_parser_js_1 = require("ua-parser-js");
17
- const _1 = require(".");
18
- const package_json_1 = __importDefault(require("../../package.json"));
19
- const classes_1 = require("../classes");
20
- const analytics_constants_1 = require("../constants/analytics.constants");
21
- const helper_1 = require("../utils/helper");
22
- var AdAction;
23
- (function (AdAction) {
24
- AdAction["Request"] = "ad_request";
25
- AdAction["Load"] = "ad_load";
26
- AdAction["Insert"] = "ad_insert";
27
- AdAction["View"] = "ad_view";
28
- AdAction["Click"] = "ad_click";
29
- AdAction["Exit"] = "ad_exit";
30
- AdAction["Pause"] = "ad_playback_pause";
31
- AdAction["Play"] = "ad_playback_play";
32
- })(AdAction || (exports.AdAction = AdAction = {}));
33
- var SessionAction;
34
- (function (SessionAction) {
35
- SessionAction["Start"] = "start";
36
- SessionAction["End"] = "end";
37
- })(SessionAction || (exports.SessionAction = SessionAction = {}));
38
- let uaParsed;
39
- try {
40
- const parser = new ua_parser_js_1.UAParser(navigator.userAgent);
41
- uaParsed = parser.getResult();
42
- }
43
- catch (e) { }
44
- class AnalyticsServiceClass extends (0, classes_1.Singleton)() {
45
- constructor() {
46
- super(...arguments);
47
- this.events = [];
48
- }
49
- init() {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- if (_1.ConfigService.sendAnalytics) {
52
- setInterval(() => {
53
- this.sendLoop();
54
- }, 1000);
55
- setTimeout(() => {
56
- this.pushSessionEvent(SessionAction.Start, {
57
- widget_id: 'blaze-sdk',
58
- });
59
- }, 0);
60
- window === null || window === void 0 ? void 0 : window.addEventListener('beforeunload', () => {
61
- this.pushSessionEvent(SessionAction.End, {
62
- widget_id: 'blaze-sdk',
63
- });
64
- });
65
- }
66
- });
67
- }
68
- sendLoop() {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- // Dont do work until we got these fields
71
- if (!_1.UserService.userId || !_1.UserService.sessionId || !this.events.length) {
72
- return;
73
- }
74
- try {
75
- const formattedEvents = this.events.map((event) => {
76
- event.user.generated_user_id = _1.UserService.userId;
77
- event.session_id = _1.UserService.sessionId;
78
- if (event.widget) {
79
- event.widget.page_view_id = _1.UserService.sessionId;
80
- }
81
- return event;
82
- });
83
- this.events = [];
84
- yield this.bulkEvent(formattedEvents);
85
- }
86
- catch (e) {
87
- console.log(e);
88
- }
89
- });
90
- }
91
- bulkEvent(body) {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- body.forEach((event) => {
94
- var _a;
95
- const action = (_a = event.event_action) !== null && _a !== void 0 ? _a : 'Unknown Action';
96
- const exposedFields = analytics_constants_1.exposedFieldsByAction[action];
97
- const filteredEvent = {};
98
- const flatEvent = (0, helper_1.flattenObject)(event);
99
- if (exposedFields) {
100
- for (const field of exposedFields) {
101
- if (flatEvent.hasOwnProperty(field)) {
102
- filteredEvent[field] = flatEvent[field];
103
- }
104
- }
105
- }
106
- _1.EventService.raiseAnalyticsEvent(action, filteredEvent);
107
- });
108
- return _1.ApiService.analyticsEvents(body);
109
- });
110
- }
111
- pushSessionEvent(action, body, label = undefined) {
112
- const event = this.setupEvent(Category.Session, action.toString(), {}, label);
113
- event.widget = body;
114
- if (action == SessionAction.End) {
115
- this.bulkEvent([event]);
116
- }
117
- else {
118
- this.events.push(event);
119
- }
120
- }
121
- pushStoryEvent(action, body, label = undefined, referrer = undefined) {
122
- this.events.push(this.setupEvent(Category.Story, action.toString(), body, label, referrer));
123
- }
124
- pushWidgetEvent(action, body, label = undefined, referrer = undefined) {
125
- this.events.push(this.setupEvent(Category.Widget, action.toString(), body, label, referrer));
126
- }
127
- setupEvent(category, action, body, label = undefined, referrer = undefined) {
128
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
129
- const event = new AnalyticsEvent();
130
- // TODO - Remove this if statement when Session is added
131
- if (category !== Category.Session)
132
- event[category] = body;
133
- event.timestamp_utc = (0, helper_1.formatUTCDate)(new Date());
134
- event.timestamp_user_tz = (0, helper_1.formatDate)(new Date());
135
- event.sdk_type = 'web';
136
- event.sdk_version = package_json_1.default.version;
137
- event.sdk_id = 'web';
138
- event.event_action = action;
139
- event.user.locale = navigator === null || navigator === void 0 ? void 0 : navigator.language;
140
- event.tech.user_agent = navigator === null || navigator === void 0 ? void 0 : navigator.userAgent;
141
- event.user.generated_user_id = _1.UserService.userId;
142
- event.session_id = _1.UserService.sessionId;
143
- event.page.page_url = location === null || location === void 0 ? void 0 : location.href;
144
- event.tech.browser = (_a = uaParsed === null || uaParsed === void 0 ? void 0 : uaParsed.browser) === null || _a === void 0 ? void 0 : _a.name;
145
- event.tech.browser_version = (_b = uaParsed === null || uaParsed === void 0 ? void 0 : uaParsed.browser) === null || _b === void 0 ? void 0 : _b.version;
146
- event.tech.os = (_c = uaParsed === null || uaParsed === void 0 ? void 0 : uaParsed.os) === null || _c === void 0 ? void 0 : _c.name;
147
- event.tech.os_version = (_d = uaParsed === null || uaParsed === void 0 ? void 0 : uaParsed.os) === null || _d === void 0 ? void 0 : _d.version;
148
- event.tech.device_model = (_e = uaParsed === null || uaParsed === void 0 ? void 0 : uaParsed.device) === null || _e === void 0 ? void 0 : _e.model;
149
- event.tech.device_brand = (_f = uaParsed === null || uaParsed === void 0 ? void 0 : uaParsed.device) === null || _f === void 0 ? void 0 : _f.vendor;
150
- event.tech.device_type = (_g = uaParsed === null || uaParsed === void 0 ? void 0 : uaParsed.device) === null || _g === void 0 ? void 0 : _g.type;
151
- event.tech.screen_resolution = `${(_h = window === null || window === void 0 ? void 0 : window.screen) === null || _h === void 0 ? void 0 : _h.availWidth}x${(_j = window === null || window === void 0 ? void 0 : window.screen) === null || _j === void 0 ? void 0 : _j.availHeight}`;
152
- event.tech.screen_color = (_l = (_k = window === null || window === void 0 ? void 0 : window.screen) === null || _k === void 0 ? void 0 : _k.colorDepth) === null || _l === void 0 ? void 0 : _l.toString();
153
- const browserWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
154
- const browserHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
155
- event.tech.browser_size = `${browserWidth}x${browserHeight}`;
156
- if ((_m = navigator.connection) === null || _m === void 0 ? void 0 : _m.type) {
157
- event.tech.connection_type = (_p = (_o = navigator.connection) === null || _o === void 0 ? void 0 : _o.type) !== null && _p !== void 0 ? _p : navigator.connection.effectiveType;
158
- }
159
- if ((_q = navigator.connection) === null || _q === void 0 ? void 0 : _q.effectiveType) {
160
- event.tech.network_domain = navigator.connection.effectiveType;
161
- }
162
- if (referrer) {
163
- event.referring = referrer;
164
- }
165
- if (label) {
166
- event.event_label = label;
167
- }
168
- event.event_category = category.toString();
169
- if (category == Category.Widget && event.widget) {
170
- event.widget.page_view_id = _1.UserService.sessionId;
171
- event.widget.page_size = event.tech.browser_size;
172
- }
173
- return event;
174
- }
175
- }
176
- exports.AnalyticsService = AnalyticsServiceClass.getInstance();
177
- var Category;
178
- (function (Category) {
179
- Category["Story"] = "story";
180
- Category["Widget"] = "widget";
181
- // Ad = 'ad',
182
- Category["Session"] = "session";
183
- })(Category || (exports.Category = Category = {}));
184
- class UserEventInfo {
185
- }
186
- class TechEventInfo {
187
- }
188
- class GeoEventInfo {
189
- }
190
- class ReferringEventInfo {
191
- }
192
- exports.ReferringEventInfo = ReferringEventInfo;
193
- class AnalyticsEvent {
194
- constructor() {
195
- this['event_label'] = '';
196
- this['session_id'] = '';
197
- this['user'] = new UserEventInfo();
198
- this['tech'] = new TechEventInfo();
199
- this['geo'] = new GeoEventInfo();
200
- this['wsc_internal'] = {
201
- customer_name: '',
202
- customer_id: '',
203
- };
204
- this['page'] = {
205
- page_url: '',
206
- };
207
- this['referring'] = new ReferringEventInfo();
208
- }
209
- }
210
- exports.AnalyticsEvent = AnalyticsEvent;
211
- class StoryEvent {
212
- }
213
- exports.StoryEvent = StoryEvent;
214
- class WidgetEvent {
215
- }
216
- exports.WidgetEvent = WidgetEvent;