@armco/analytics 0.0.5 → 0.0.6
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/dist/analytics.d.ts +1 -1
- package/dist/analytics.js +8 -11
- package/dist/helper.d.ts +1 -0
- package/dist/helper.js +3 -0
- package/package.json +1 -1
package/dist/analytics.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ declare function trackPageView(pageName: string, data?: {
|
|
|
9
9
|
[key: string]: any;
|
|
10
10
|
}): void;
|
|
11
11
|
declare function trackError(errorMessage: string): void;
|
|
12
|
-
declare function enableTracking(
|
|
12
|
+
declare function enableTracking(enable: boolean): void;
|
|
13
13
|
declare function generateAnonymousId(): string;
|
|
14
14
|
declare function identify(appUser: User): void;
|
|
15
15
|
declare function sendHostProjectName(): void;
|
package/dist/analytics.js
CHANGED
|
@@ -14,6 +14,7 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
14
14
|
import { ADD, ARMCO_SERVER } from "./constants";
|
|
15
15
|
import { startSession, getSessionId, terminateSession } from "./session";
|
|
16
16
|
import { ipLookup, success, error, localTimeRegion } from "./location";
|
|
17
|
+
import { isArClient } from './helper';
|
|
17
18
|
import { hookFlushHandlers, queueEvent } from './flush';
|
|
18
19
|
const tsConfigPath = getEnvironmentType() === "node" ? path.resolve(process.cwd(), 'tsconfig.json') : "../../../../tsConfig.json";
|
|
19
20
|
const packageJsonPath = getEnvironmentType() === "node" ? path.resolve(process.cwd(), 'package.json') : "../../../../package.json";
|
|
@@ -120,6 +121,8 @@ function enrichEventData(data) {
|
|
|
120
121
|
coordinates && !data.coordinates && (data.coordinates = coordinates);
|
|
121
122
|
!data.timestamp && (data.timestamp = new Date());
|
|
122
123
|
!data.userId && (data.userId = user ? user.email : ar_anonymous_id);
|
|
124
|
+
!data.email && user && user.email && (data.email = user.email);
|
|
125
|
+
user && (data.user = user);
|
|
123
126
|
}
|
|
124
127
|
}
|
|
125
128
|
function validateEvent(data) {
|
|
@@ -184,7 +187,8 @@ function tagEvents(email) {
|
|
|
184
187
|
});
|
|
185
188
|
}
|
|
186
189
|
function trackEvent(event, data) {
|
|
187
|
-
|
|
190
|
+
const tracker = user && user.email ? user.email : ar_anonymous_id;
|
|
191
|
+
if (enabled && tracker) {
|
|
188
192
|
if (typeof event === "string") {
|
|
189
193
|
data = data || {};
|
|
190
194
|
if (data) {
|
|
@@ -194,18 +198,11 @@ function trackEvent(event, data) {
|
|
|
194
198
|
else {
|
|
195
199
|
data = event;
|
|
196
200
|
}
|
|
197
|
-
if (user.email) {
|
|
198
|
-
data.email = user.email;
|
|
199
|
-
}
|
|
200
|
-
data.user = user;
|
|
201
201
|
if (!validateEvent(data)) {
|
|
202
202
|
console.error("Attempting to send empty event, or event missing eventType, failing send...");
|
|
203
203
|
return;
|
|
204
204
|
}
|
|
205
205
|
enrichEventData(data);
|
|
206
|
-
if (hostProjectName && hostProjectName.startsWith("@armco")) {
|
|
207
|
-
enableTracking(true);
|
|
208
|
-
}
|
|
209
206
|
(CONFIG === null || CONFIG === void 0 ? void 0 : CONFIG.submissionStrategy) === "DEFER" ? queueEvent(data) : sendAnalyticsData(data);
|
|
210
207
|
}
|
|
211
208
|
else {
|
|
@@ -229,13 +226,13 @@ function isEnabled() {
|
|
|
229
226
|
const doNotTrackValue = navigator.doNotTrack;
|
|
230
227
|
if (doNotTrackValue === '1' || doNotTrackValue === 'yes') {
|
|
231
228
|
console.warn("[ANALYTICS] Tracking disabled in client, events will not be logged!");
|
|
232
|
-
return false;
|
|
229
|
+
return isArClient(hostProjectName) || false;
|
|
233
230
|
}
|
|
234
231
|
}
|
|
235
232
|
return true;
|
|
236
233
|
}
|
|
237
|
-
function enableTracking(
|
|
238
|
-
enabled = isEnabled;
|
|
234
|
+
function enableTracking(enable) {
|
|
235
|
+
enabled = isEnabled() && enable;
|
|
239
236
|
}
|
|
240
237
|
function generateAnonymousId() {
|
|
241
238
|
ar_anonymous_id = uuidv4();
|
package/dist/helper.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isArClient(name: string | null): boolean;
|
package/dist/helper.js
ADDED