saasco-sdk 0.1.0
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 +504 -0
- package/package.json +13 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +4 -0
- package/src/index.js.map +1 -0
- package/src/lib/analytics.d.ts +77 -0
- package/src/lib/analytics.js +277 -0
- package/src/lib/analytics.js.map +1 -0
- package/src/lib/coerceReservedProperties.d.ts +2 -0
- package/src/lib/coerceReservedProperties.js +305 -0
- package/src/lib/coerceReservedProperties.js.map +1 -0
- package/src/lib/self-execute-analytics.d.ts +6 -0
- package/src/lib/self-execute-analytics.js +38 -0
- package/src/lib/self-execute-analytics.js.map +1 -0
- package/src/lib/timezones.d.ts +3 -0
- package/src/lib/timezones.js +428 -0
- package/src/lib/timezones.js.map +1 -0
- package/src/lib/types.d.ts +1303 -0
- package/src/lib/types.js +177 -0
- package/src/lib/types.js.map +1 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { v4 as uuid } from '@lukeed/uuid';
|
|
3
|
+
import { timezones } from './timezones';
|
|
4
|
+
let userId = null;
|
|
5
|
+
const PREF = 'saasco-analytics';
|
|
6
|
+
function storeData(key, value, ttl) {
|
|
7
|
+
const fullKey = `${PREF}-${key}`;
|
|
8
|
+
if (value === undefined)
|
|
9
|
+
return window.localStorage.removeItem(fullKey);
|
|
10
|
+
const now = new Date();
|
|
11
|
+
const item = {
|
|
12
|
+
value,
|
|
13
|
+
expiry: now.getTime() + ttl,
|
|
14
|
+
};
|
|
15
|
+
localStorage.setItem(fullKey, JSON.stringify(item));
|
|
16
|
+
}
|
|
17
|
+
function retrieveData(key) {
|
|
18
|
+
const fullKey = `${PREF}-${key}`;
|
|
19
|
+
const itemStr = localStorage.getItem(fullKey);
|
|
20
|
+
if (!itemStr) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const item = JSON.parse(itemStr);
|
|
24
|
+
const now = new Date();
|
|
25
|
+
if (now.getTime() > item.expiry) {
|
|
26
|
+
localStorage.removeItem(fullKey);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return item.value;
|
|
30
|
+
}
|
|
31
|
+
function getSessionId() {
|
|
32
|
+
return retrieveData(`session-id`);
|
|
33
|
+
}
|
|
34
|
+
function setSessionId({ reset } = { reset: false }) {
|
|
35
|
+
const sessionId = reset ? uuid() : getSessionId() || uuid();
|
|
36
|
+
storeData(`session-id`, sessionId, 1000 * 60 * 30);
|
|
37
|
+
}
|
|
38
|
+
function getAnonymousId() {
|
|
39
|
+
return retrieveData(`anonymous-id`);
|
|
40
|
+
}
|
|
41
|
+
function setAnonmousId({ reset } = { reset: false }) {
|
|
42
|
+
const anonymousId = reset ? uuid() : getAnonymousId() || uuid();
|
|
43
|
+
storeData(`anonymous-id`, anonymousId, 1000 * 60 * 60 * 24 * 365);
|
|
44
|
+
return anonymousId;
|
|
45
|
+
}
|
|
46
|
+
export class Analytics {
|
|
47
|
+
/**
|
|
48
|
+
* Creates an instance of Analytics.
|
|
49
|
+
* @param config Configuration options for analytics.
|
|
50
|
+
* @param config.projectId The unique identifier for the project.
|
|
51
|
+
* @param config.proxy The URL of the proxy server to use, if any.
|
|
52
|
+
* @param config.autoPageTracking Whether to automatically track page views. Default is false.
|
|
53
|
+
* @param config.enabled Whether analytics is enabled. Default is true. Set to false for development and staging envioronments. Will still allow debug mode to be true, just no events will be sent
|
|
54
|
+
* @param config.debug Whether to log debug information. Default is false.
|
|
55
|
+
*/
|
|
56
|
+
constructor(config) {
|
|
57
|
+
this.config = config;
|
|
58
|
+
this.lastPageViewHref = '';
|
|
59
|
+
// default enabled to true
|
|
60
|
+
this.config.enabled =
|
|
61
|
+
this.config.enabled === undefined ? true : this.config.enabled;
|
|
62
|
+
this.init();
|
|
63
|
+
}
|
|
64
|
+
init() {
|
|
65
|
+
this.initiAutoPageTracking();
|
|
66
|
+
this.log('Analytics initialized', this.config);
|
|
67
|
+
}
|
|
68
|
+
debug(value) {
|
|
69
|
+
this.config.debug = value;
|
|
70
|
+
this.log(`Debug mode ${value ? 'activated' : 'deactivated'}.`);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The track method lets you record the actions your users perform.
|
|
74
|
+
* Its good to keep a conistent naming convention for your events.
|
|
75
|
+
* We like the Object Action Framework from segment:
|
|
76
|
+
* https://segment.com/academy/collecting-data/naming-conventions-for-clean-data/
|
|
77
|
+
*
|
|
78
|
+
* @param name The name of the event eg "Song Played"
|
|
79
|
+
* @param properties The properties of the event eg { genre: "Classics", song: "Never Gonna Give You Up" }
|
|
80
|
+
*/
|
|
81
|
+
track(name,
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
+
properties) {
|
|
84
|
+
var _a;
|
|
85
|
+
// Prevent duplicate Page View tracking
|
|
86
|
+
if (name === 'Page View') {
|
|
87
|
+
const pageViewHref = window.location.href;
|
|
88
|
+
if (pageViewHref === this.lastPageViewHref)
|
|
89
|
+
return;
|
|
90
|
+
this.lastPageViewHref = pageViewHref;
|
|
91
|
+
}
|
|
92
|
+
setSessionId();
|
|
93
|
+
setAnonmousId();
|
|
94
|
+
const customNavigator = navigator;
|
|
95
|
+
const locale = customNavigator.languages && customNavigator.languages.length
|
|
96
|
+
? customNavigator.languages[0]
|
|
97
|
+
: customNavigator.userLanguage ||
|
|
98
|
+
customNavigator.language ||
|
|
99
|
+
customNavigator.browserLanguage ||
|
|
100
|
+
'en';
|
|
101
|
+
// https://caniuse.com/?search=Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
102
|
+
// Only has 96.63% global support, so we need to check for undefined
|
|
103
|
+
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
104
|
+
const location = timezones[timezone] || ((_a = locale === null || locale === void 0 ? void 0 : locale.split('-')) === null || _a === void 0 ? void 0 : _a[1]) || 'undefined';
|
|
105
|
+
const $screenHeight = screen.height;
|
|
106
|
+
const $screenWidth = screen.width;
|
|
107
|
+
const $screenDPI = window.devicePixelRatio;
|
|
108
|
+
const $referrer = document.referrer;
|
|
109
|
+
const $utm_source = this.getSearchParam('utm_source');
|
|
110
|
+
const $utm_medium = this.getSearchParam('utm_medium');
|
|
111
|
+
const $utm_campaign = this.getSearchParam('utm_campaign');
|
|
112
|
+
const $utm_content = this.getSearchParam('utm_content');
|
|
113
|
+
const $utm_term = this.getSearchParam('utm_term');
|
|
114
|
+
const $gclid = this.getSearchParam('gclid');
|
|
115
|
+
const $fbclid = this.getSearchParam('fbclid');
|
|
116
|
+
const data = {
|
|
117
|
+
id: uuid(),
|
|
118
|
+
timestamp: new Date().toISOString(),
|
|
119
|
+
action: name,
|
|
120
|
+
version: '1',
|
|
121
|
+
sessionId: getSessionId(),
|
|
122
|
+
anonymousId: getAnonymousId(),
|
|
123
|
+
projectId: this.config.projectId,
|
|
124
|
+
payload: JSON.stringify({
|
|
125
|
+
'user-agent': window.navigator.userAgent,
|
|
126
|
+
locale,
|
|
127
|
+
location,
|
|
128
|
+
title: document.title,
|
|
129
|
+
pathname: window.location.pathname,
|
|
130
|
+
href: window.location.href,
|
|
131
|
+
$screenHeight,
|
|
132
|
+
$screenWidth,
|
|
133
|
+
$screenDPI,
|
|
134
|
+
$referrer,
|
|
135
|
+
$utm_source,
|
|
136
|
+
$utm_medium,
|
|
137
|
+
$utm_campaign,
|
|
138
|
+
$utm_content,
|
|
139
|
+
$utm_term,
|
|
140
|
+
$gclid,
|
|
141
|
+
$fbclid,
|
|
142
|
+
properties: properties || {},
|
|
143
|
+
}),
|
|
144
|
+
};
|
|
145
|
+
this.doRequest('events', data);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The page method lets you record page views on your website
|
|
149
|
+
* This records the page title and path and names the event useing the reserved property "Page Viewed"
|
|
150
|
+
*
|
|
151
|
+
* Before implementing this make sure you have disabled the autoPageTracking in the config or you will get duplicate page views
|
|
152
|
+
*/
|
|
153
|
+
page() {
|
|
154
|
+
this.track('Page View');
|
|
155
|
+
}
|
|
156
|
+
identify(distinctIdOrProperties, propertiesOrOptions, optionsOrNothing) {
|
|
157
|
+
const hasId = typeof distinctIdOrProperties === 'string' ||
|
|
158
|
+
typeof distinctIdOrProperties === 'number' ||
|
|
159
|
+
distinctIdOrProperties === null;
|
|
160
|
+
const distinctId = (hasId ? distinctIdOrProperties === null || distinctIdOrProperties === void 0 ? void 0 : distinctIdOrProperties.toString() : `soft_${uuid()}`);
|
|
161
|
+
const properties = (hasId ? propertiesOrOptions : distinctIdOrProperties);
|
|
162
|
+
const options = (hasId ? optionsOrNothing : propertiesOrOptions);
|
|
163
|
+
// When the user gets identified as null this will reset the users session and anonymous id
|
|
164
|
+
// This should only be called when distinctId is null and there is an existing userId.
|
|
165
|
+
// This means the user has logged out and we should reset the session and anonymous IDs
|
|
166
|
+
const reset = !distinctId && !!userId;
|
|
167
|
+
if (reset)
|
|
168
|
+
this.log('User logged out and session reset');
|
|
169
|
+
setSessionId({ reset });
|
|
170
|
+
const anonymousId = setAnonmousId({ reset });
|
|
171
|
+
// set the distinct Id to the userId
|
|
172
|
+
userId = distinctId;
|
|
173
|
+
// No distinctId provided so we don't track the user
|
|
174
|
+
if (!distinctId)
|
|
175
|
+
return;
|
|
176
|
+
const data = {
|
|
177
|
+
id: uuid(),
|
|
178
|
+
timestamp: new Date().toISOString(),
|
|
179
|
+
projectId: this.config.projectId,
|
|
180
|
+
distinctId,
|
|
181
|
+
anonymousId,
|
|
182
|
+
version: '1',
|
|
183
|
+
payload: properties || {},
|
|
184
|
+
options: options || {},
|
|
185
|
+
};
|
|
186
|
+
this.doRequest('identify', data);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Handles sending data to the Saasco Analytics API
|
|
190
|
+
* If you have a proxy set up, it will send the data to the proxy and you can handle forawrding the data to the Saasco events API
|
|
191
|
+
* @param path
|
|
192
|
+
* @param data
|
|
193
|
+
*/
|
|
194
|
+
doRequest(path, data) {
|
|
195
|
+
const base = this.config.proxy || 'https://www.saasco.com/api/';
|
|
196
|
+
const url = `${base}${path}`;
|
|
197
|
+
const logMessage = data.action === 'Page View'
|
|
198
|
+
? `Page View ${window.location.pathname}` // if its a page view, include pathname in console log
|
|
199
|
+
: data.action || path;
|
|
200
|
+
this.log(logMessage, data);
|
|
201
|
+
// If analytics is disabled, don't send the request
|
|
202
|
+
if (this.config.enabled === false)
|
|
203
|
+
return;
|
|
204
|
+
fetch(url, {
|
|
205
|
+
method: 'POST',
|
|
206
|
+
headers: {
|
|
207
|
+
'Content-Type': 'application/json',
|
|
208
|
+
},
|
|
209
|
+
body: JSON.stringify(data),
|
|
210
|
+
})
|
|
211
|
+
.then((response) => {
|
|
212
|
+
if (!response.ok) {
|
|
213
|
+
throw new Error(response.status.toString());
|
|
214
|
+
}
|
|
215
|
+
})
|
|
216
|
+
.catch((e) => {
|
|
217
|
+
console.error('Error with Saasco Analytics request: ' + e.message, path, data);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* @param args Arguments to be logged
|
|
222
|
+
*/
|
|
223
|
+
log(...args) {
|
|
224
|
+
if (!this.config.debug)
|
|
225
|
+
return;
|
|
226
|
+
const message = '◍ Saasco Analytics Debug';
|
|
227
|
+
console.log(...[
|
|
228
|
+
`\x1b[47m\x1b[30m ${message} \x1b[0m`, // Message highlighted for easy finding
|
|
229
|
+
...args,
|
|
230
|
+
]);
|
|
231
|
+
}
|
|
232
|
+
getSearchParam(param) {
|
|
233
|
+
return new URLSearchParams(window.location.search).get(param);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* If autoPageTracking is enabled, this will automatically track page views
|
|
237
|
+
* It listens to url changes to track new pages every time the url changes
|
|
238
|
+
* @returns
|
|
239
|
+
*/
|
|
240
|
+
initiAutoPageTracking() {
|
|
241
|
+
// Disable auto page tracking if the config is set to false
|
|
242
|
+
// Will run if undefined or true
|
|
243
|
+
if (this.config.autoPageTracking === false)
|
|
244
|
+
return;
|
|
245
|
+
// Prevent running on the server
|
|
246
|
+
if (typeof window === 'undefined')
|
|
247
|
+
return;
|
|
248
|
+
// Prevent intitializing auto page tracking more than once
|
|
249
|
+
if (window.saascoAutoPageTrackingActive) {
|
|
250
|
+
this.log('Auto Page Tracking already enabled');
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
window.saascoAutoPageTrackingActive = true;
|
|
254
|
+
this.log('Auto Page Tracking enabled');
|
|
255
|
+
// Track initial page load
|
|
256
|
+
this.page();
|
|
257
|
+
// Listen for hash changes
|
|
258
|
+
window.addEventListener('hashchange', () => this.page());
|
|
259
|
+
// Listen to popstate for back and forward navigation
|
|
260
|
+
window.addEventListener('popstate', () => this.page());
|
|
261
|
+
// Wrap history push state to listen for URL changes
|
|
262
|
+
const historyPushState = history.pushState;
|
|
263
|
+
history.pushState = (...args) => {
|
|
264
|
+
const returnValue = historyPushState.apply(history, args);
|
|
265
|
+
this.page();
|
|
266
|
+
return returnValue;
|
|
267
|
+
};
|
|
268
|
+
// Wrap history replace state to listen for URL changes
|
|
269
|
+
const historyReplaceState = history.replaceState;
|
|
270
|
+
history.replaceState = (...args) => {
|
|
271
|
+
const returnValue = historyReplaceState.apply(history, args);
|
|
272
|
+
this.page();
|
|
273
|
+
return returnValue;
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=analytics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../../../../libs/analytics/shared/src/lib/analytics.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AASxC,IAAI,MAAM,GAAkB,IAAI,CAAC;AAEjC,MAAM,IAAI,GAAG,kBAAkB,CAAC;AAOhC,SAA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,OAAO,WAAW,CAAC;QACrB,CAAC,CAAC;QAEF,uDAAuD;QACvD,MAAM,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC;QACjD,OAAO,CAAC,YAAY,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE;YACjC,MAAM,WAAW,GAAG,mBAAmB,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC7D,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,OAAO,WAAW,CAAC;QACrB,CAAC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export function coerceReservedProperties(properties) {
|
|
3
|
+
const coerce = [
|
|
4
|
+
{
|
|
5
|
+
key: 'age',
|
|
6
|
+
coerceFrom: [
|
|
7
|
+
'age',
|
|
8
|
+
'age_value',
|
|
9
|
+
'ageValue',
|
|
10
|
+
'user_age',
|
|
11
|
+
'userAge',
|
|
12
|
+
'user_age_value',
|
|
13
|
+
'userAgeValue',
|
|
14
|
+
'age_of_user',
|
|
15
|
+
'ageOfUser',
|
|
16
|
+
'age_in_years',
|
|
17
|
+
'ageInYears',
|
|
18
|
+
'years_old',
|
|
19
|
+
'yearsOld',
|
|
20
|
+
'age_years',
|
|
21
|
+
'ageYears',
|
|
22
|
+
],
|
|
23
|
+
schema: z.coerce.number().optional(),
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
key: 'avatar',
|
|
27
|
+
coerceFrom: [
|
|
28
|
+
'avatar',
|
|
29
|
+
'user_avatar',
|
|
30
|
+
'userAvatar',
|
|
31
|
+
'avatar_url',
|
|
32
|
+
'avatarUrl',
|
|
33
|
+
'profile_picture',
|
|
34
|
+
'profilePicture',
|
|
35
|
+
'picture',
|
|
36
|
+
'user_picture',
|
|
37
|
+
'userPicture',
|
|
38
|
+
'profile_pic',
|
|
39
|
+
'profilePic',
|
|
40
|
+
'pic',
|
|
41
|
+
'user_pic',
|
|
42
|
+
'userPic',
|
|
43
|
+
'image',
|
|
44
|
+
'user_image',
|
|
45
|
+
'userImage',
|
|
46
|
+
'profile_image',
|
|
47
|
+
'profileImage',
|
|
48
|
+
'profile_image_url',
|
|
49
|
+
'profileImageUrl',
|
|
50
|
+
'profile_pic_url',
|
|
51
|
+
'profilePicUrl',
|
|
52
|
+
'pic_url',
|
|
53
|
+
'picUrl',
|
|
54
|
+
'image_url',
|
|
55
|
+
'imageUrl',
|
|
56
|
+
'user_image_url',
|
|
57
|
+
'userImageUrl',
|
|
58
|
+
'user_pic_url',
|
|
59
|
+
'userPicUrl',
|
|
60
|
+
'profile_pic_url',
|
|
61
|
+
'profilePicUrl',
|
|
62
|
+
'pic_url',
|
|
63
|
+
'picUrl',
|
|
64
|
+
'image_url',
|
|
65
|
+
'imageUrl',
|
|
66
|
+
'user_image_url',
|
|
67
|
+
'userImageUrl',
|
|
68
|
+
'user_pic_url',
|
|
69
|
+
'userPicUrl',
|
|
70
|
+
],
|
|
71
|
+
schema: z.coerce.string().url().optional(),
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
key: 'birthday',
|
|
75
|
+
coerceFrom: [
|
|
76
|
+
'birthday',
|
|
77
|
+
'birth_date',
|
|
78
|
+
'birthDate',
|
|
79
|
+
'date_of_birth',
|
|
80
|
+
'dateOfBirth',
|
|
81
|
+
'dob',
|
|
82
|
+
'Dob',
|
|
83
|
+
'birth_day',
|
|
84
|
+
'birthDay',
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
key: 'createdAt',
|
|
89
|
+
coerceFrom: [
|
|
90
|
+
'createdAt',
|
|
91
|
+
'created_at',
|
|
92
|
+
'created',
|
|
93
|
+
'createdDate',
|
|
94
|
+
'created_date',
|
|
95
|
+
'dateCreated',
|
|
96
|
+
'date_created',
|
|
97
|
+
'date_created_at',
|
|
98
|
+
'dateCreatedAt',
|
|
99
|
+
'date_created_at',
|
|
100
|
+
'dateCreated',
|
|
101
|
+
'date_created',
|
|
102
|
+
],
|
|
103
|
+
schema: z.coerce.date().optional(),
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
key: 'description',
|
|
107
|
+
coerceFrom: [
|
|
108
|
+
'description',
|
|
109
|
+
'bio',
|
|
110
|
+
'about',
|
|
111
|
+
'about_me',
|
|
112
|
+
'aboutMe',
|
|
113
|
+
'user_description',
|
|
114
|
+
'userDescription',
|
|
115
|
+
'profile_description',
|
|
116
|
+
'profileDescription',
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
key: 'email',
|
|
121
|
+
coerceFrom: [
|
|
122
|
+
'email',
|
|
123
|
+
'user_email',
|
|
124
|
+
'userEmail',
|
|
125
|
+
'email_address',
|
|
126
|
+
'emailAddress',
|
|
127
|
+
'e_mail',
|
|
128
|
+
'E_Mail',
|
|
129
|
+
'mail',
|
|
130
|
+
'Mail',
|
|
131
|
+
'contact_email',
|
|
132
|
+
'contactEmail',
|
|
133
|
+
'primary_email',
|
|
134
|
+
'primaryEmail',
|
|
135
|
+
],
|
|
136
|
+
schema: z.coerce.string().email().optional(),
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
key: 'firstName',
|
|
140
|
+
coerceFrom: [
|
|
141
|
+
'first_name',
|
|
142
|
+
'firstName',
|
|
143
|
+
'firstname',
|
|
144
|
+
'given_name',
|
|
145
|
+
'givenName',
|
|
146
|
+
'user_first_name',
|
|
147
|
+
'userFirstName',
|
|
148
|
+
'name_first',
|
|
149
|
+
'nameFirst',
|
|
150
|
+
'f_name',
|
|
151
|
+
'fName',
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
key: 'gender',
|
|
156
|
+
coerceFrom: [
|
|
157
|
+
'gender',
|
|
158
|
+
'user_gender',
|
|
159
|
+
'userGender',
|
|
160
|
+
'sex',
|
|
161
|
+
'user_sex',
|
|
162
|
+
'userSex',
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
key: 'lastName',
|
|
167
|
+
coerceFrom: [
|
|
168
|
+
'last_name',
|
|
169
|
+
'lastName',
|
|
170
|
+
'lastname',
|
|
171
|
+
'surname',
|
|
172
|
+
'user_last_name',
|
|
173
|
+
'userLastName',
|
|
174
|
+
'name_last',
|
|
175
|
+
'nameLast',
|
|
176
|
+
'l_name',
|
|
177
|
+
'lName',
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
key: 'name',
|
|
182
|
+
coerceFrom: [
|
|
183
|
+
'name',
|
|
184
|
+
'full_name',
|
|
185
|
+
'fullName',
|
|
186
|
+
'user_name',
|
|
187
|
+
'userName',
|
|
188
|
+
'complete_name',
|
|
189
|
+
'completeName',
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
key: 'phone',
|
|
194
|
+
coerceFrom: [
|
|
195
|
+
'phone',
|
|
196
|
+
'phone_number',
|
|
197
|
+
'phoneNumber',
|
|
198
|
+
'mobile',
|
|
199
|
+
'mobile_number',
|
|
200
|
+
'mobileNumber',
|
|
201
|
+
'contact_number',
|
|
202
|
+
'contactNumber',
|
|
203
|
+
'tel',
|
|
204
|
+
'telephone',
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
key: 'title',
|
|
209
|
+
coerceFrom: [
|
|
210
|
+
'title',
|
|
211
|
+
'user_title',
|
|
212
|
+
'userTitle',
|
|
213
|
+
'position',
|
|
214
|
+
'job_title',
|
|
215
|
+
'jobTitle',
|
|
216
|
+
],
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
key: 'username',
|
|
220
|
+
coerceFrom: [
|
|
221
|
+
'username',
|
|
222
|
+
'user_name',
|
|
223
|
+
'userName',
|
|
224
|
+
'user_login',
|
|
225
|
+
'userLogin',
|
|
226
|
+
'account_name',
|
|
227
|
+
'accountName',
|
|
228
|
+
'screen_name',
|
|
229
|
+
'screenName',
|
|
230
|
+
'handle',
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
key: 'website',
|
|
235
|
+
coerceFrom: [
|
|
236
|
+
'website',
|
|
237
|
+
'web_site',
|
|
238
|
+
'site',
|
|
239
|
+
'web',
|
|
240
|
+
'personal_website',
|
|
241
|
+
'personalWebsite',
|
|
242
|
+
'company_website',
|
|
243
|
+
'companyWebsite',
|
|
244
|
+
],
|
|
245
|
+
schema: z.coerce.string().url().optional(),
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
key: 'displayName',
|
|
249
|
+
coerceFrom: [
|
|
250
|
+
'display_name',
|
|
251
|
+
'displayName',
|
|
252
|
+
'user_display_name',
|
|
253
|
+
'userDisplayName',
|
|
254
|
+
'full_name',
|
|
255
|
+
'fullName',
|
|
256
|
+
'user_full_name',
|
|
257
|
+
'userFullName',
|
|
258
|
+
'complete_name',
|
|
259
|
+
'completeName',
|
|
260
|
+
'user_complete_name',
|
|
261
|
+
'userCompleteName',
|
|
262
|
+
'name',
|
|
263
|
+
'username',
|
|
264
|
+
],
|
|
265
|
+
schema: z.coerce.string().url().optional(),
|
|
266
|
+
},
|
|
267
|
+
];
|
|
268
|
+
return coerce.reduce((acc, { key, coerceFrom, schema }) => {
|
|
269
|
+
const coercedValue = coerceValue(properties, coerceFrom, schema);
|
|
270
|
+
if (coercedValue)
|
|
271
|
+
acc[key] = coercedValue;
|
|
272
|
+
if (!coercedValue && key === 'displayName' && acc['firstName']) {
|
|
273
|
+
const displayName = `${acc['firstName'] || ''} ${acc['lastName'] || ''}`.trim();
|
|
274
|
+
if (displayName)
|
|
275
|
+
acc[key] = displayName;
|
|
276
|
+
}
|
|
277
|
+
return acc;
|
|
278
|
+
}, properties);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Coerces the first non-null value from the properties object
|
|
282
|
+
* @param properties
|
|
283
|
+
* @param keys Provided in priority order, the first to match will return
|
|
284
|
+
* @returns
|
|
285
|
+
*/
|
|
286
|
+
function coerceValue(properties, keys, schema) {
|
|
287
|
+
let coercedValue = null;
|
|
288
|
+
for (const key of keys) {
|
|
289
|
+
if (properties[key] !== undefined) {
|
|
290
|
+
if (!schema) {
|
|
291
|
+
coercedValue = properties[key];
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
const result = schema.safeParse(properties[key]);
|
|
296
|
+
if (result.success) {
|
|
297
|
+
coercedValue = properties[key];
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return coercedValue;
|
|
304
|
+
}
|
|
305
|
+
//# sourceMappingURL=coerceReservedProperties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerceReservedProperties.js","sourceRoot":"","sources":["../../../../libs/analytics/shared/src/lib/coerceReservedProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,UAAU,wBAAwB,CACtC,UAAmC;IAEnC,MAAM,MAAM,GAA+D;QACzE;YACE,GAAG,EAAE,KAAK;YACV,UAAU,EAAE;gBACV,KAAK;gBACL,WAAW;gBACX,UAAU;gBACV,UAAU;gBACV,SAAS;gBACT,gBAAgB;gBAChB,cAAc;gBACd,aAAa;gBACb,WAAW;gBACX,cAAc;gBACd,YAAY;gBACZ,WAAW;gBACX,UAAU;gBACV,WAAW;gBACX,UAAU;aACX;YACD,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;SACrC;QACD;YACE,GAAG,EAAE,QAAQ;YACb,UAAU,EAAE;gBACV,QAAQ;gBACR,aAAa;gBACb,YAAY;gBACZ,YAAY;gBACZ,WAAW;gBACX,iBAAiB;gBACjB,gBAAgB;gBAChB,SAAS;gBACT,cAAc;gBACd,aAAa;gBACb,aAAa;gBACb,YAAY;gBACZ,KAAK;gBACL,UAAU;gBACV,SAAS;gBACT,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AAC;IACb,CAAC,EAAE,UAAU,CAAC,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAClB,UAAmC,EACnC,IAAc,EACd,MAAiB;IAEjB,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;YAClC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,YAAY,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;gBAC/B,MAAM;YACR,CAAC;iBAAM,CAAC;gBACN,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;gBACjD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;oBACnB,YAAY,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;oBAC/B,MAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Analytics } from './analytics';
|
|
2
|
+
(function () {
|
|
3
|
+
const scriptTags = document.getElementsByTagName('script');
|
|
4
|
+
let projectId = undefined;
|
|
5
|
+
let proxy = undefined;
|
|
6
|
+
let autoPageTracking = undefined;
|
|
7
|
+
let enabled = undefined;
|
|
8
|
+
let debug = undefined;
|
|
9
|
+
for (let i = 0; i < scriptTags.length; i++) {
|
|
10
|
+
const src = scriptTags[i].getAttribute('src');
|
|
11
|
+
if (src && src.includes('analytics-sdk.js')) {
|
|
12
|
+
projectId = scriptTags[i].getAttribute('data-projectId') || undefined;
|
|
13
|
+
proxy = scriptTags[i].getAttribute('data-proxy') || undefined;
|
|
14
|
+
autoPageTracking =
|
|
15
|
+
scriptTags[i].getAttribute('data-autoPageTracking') !== 'false';
|
|
16
|
+
enabled = scriptTags[i].getAttribute('data-enabled') !== 'false';
|
|
17
|
+
debug = scriptTags[i].getAttribute('data-debug') !== 'false';
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (typeof window === 'undefined') {
|
|
22
|
+
return console.error('Window is undefined. The Saasco Analytics SDK only runs on the client.');
|
|
23
|
+
}
|
|
24
|
+
if (projectId) {
|
|
25
|
+
const analytics = new Analytics({
|
|
26
|
+
projectId,
|
|
27
|
+
proxy,
|
|
28
|
+
autoPageTracking,
|
|
29
|
+
enabled,
|
|
30
|
+
debug,
|
|
31
|
+
});
|
|
32
|
+
window.analytics = analytics;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.error('No projectId found for Saasco Analytics SDK');
|
|
36
|
+
}
|
|
37
|
+
})();
|
|
38
|
+
//# sourceMappingURL=self-execute-analytics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self-execute-analytics.js","sourceRoot":"","sources":["../../../../libs/analytics/shared/src/lib/self-execute-analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAQxC,CAAC;IACC,MAAM,UAAU,GAAG,QAAQ,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAC3D,IAAI,SAAS,GAAuB,SAAS,CAAC;IAC9C,IAAI,KAAK,GAAuB,SAAS,CAAC;IAC1C,IAAI,gBAAgB,GAAwB,SAAS,CAAC;IACtD,IAAI,OAAO,GAAwB,SAAS,CAAC;IAC7C,IAAI,KAAK,GAAwB,SAAS,CAAC;IAE3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,MAAM,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAC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