@armco/analytics 0.0.5 → 0.0.7
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 +9 -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";
|
|
@@ -106,6 +107,7 @@ function getHostProjectName() {
|
|
|
106
107
|
if (!hostProjectName) {
|
|
107
108
|
const packageJson = yield import(packageJsonPath);
|
|
108
109
|
hostProjectName = packageJson.name || null;
|
|
110
|
+
enabled = isEnabled();
|
|
109
111
|
}
|
|
110
112
|
return hostProjectName;
|
|
111
113
|
});
|
|
@@ -120,6 +122,8 @@ function enrichEventData(data) {
|
|
|
120
122
|
coordinates && !data.coordinates && (data.coordinates = coordinates);
|
|
121
123
|
!data.timestamp && (data.timestamp = new Date());
|
|
122
124
|
!data.userId && (data.userId = user ? user.email : ar_anonymous_id);
|
|
125
|
+
!data.email && user && user.email && (data.email = user.email);
|
|
126
|
+
user && (data.user = user);
|
|
123
127
|
}
|
|
124
128
|
}
|
|
125
129
|
function validateEvent(data) {
|
|
@@ -184,7 +188,8 @@ function tagEvents(email) {
|
|
|
184
188
|
});
|
|
185
189
|
}
|
|
186
190
|
function trackEvent(event, data) {
|
|
187
|
-
|
|
191
|
+
const tracker = user && user.email ? user.email : ar_anonymous_id;
|
|
192
|
+
if (enabled && tracker) {
|
|
188
193
|
if (typeof event === "string") {
|
|
189
194
|
data = data || {};
|
|
190
195
|
if (data) {
|
|
@@ -194,18 +199,11 @@ function trackEvent(event, data) {
|
|
|
194
199
|
else {
|
|
195
200
|
data = event;
|
|
196
201
|
}
|
|
197
|
-
if (user.email) {
|
|
198
|
-
data.email = user.email;
|
|
199
|
-
}
|
|
200
|
-
data.user = user;
|
|
201
202
|
if (!validateEvent(data)) {
|
|
202
203
|
console.error("Attempting to send empty event, or event missing eventType, failing send...");
|
|
203
204
|
return;
|
|
204
205
|
}
|
|
205
206
|
enrichEventData(data);
|
|
206
|
-
if (hostProjectName && hostProjectName.startsWith("@armco")) {
|
|
207
|
-
enableTracking(true);
|
|
208
|
-
}
|
|
209
207
|
(CONFIG === null || CONFIG === void 0 ? void 0 : CONFIG.submissionStrategy) === "DEFER" ? queueEvent(data) : sendAnalyticsData(data);
|
|
210
208
|
}
|
|
211
209
|
else {
|
|
@@ -229,13 +227,13 @@ function isEnabled() {
|
|
|
229
227
|
const doNotTrackValue = navigator.doNotTrack;
|
|
230
228
|
if (doNotTrackValue === '1' || doNotTrackValue === 'yes') {
|
|
231
229
|
console.warn("[ANALYTICS] Tracking disabled in client, events will not be logged!");
|
|
232
|
-
return false;
|
|
230
|
+
return isArClient(hostProjectName) || false;
|
|
233
231
|
}
|
|
234
232
|
}
|
|
235
233
|
return true;
|
|
236
234
|
}
|
|
237
|
-
function enableTracking(
|
|
238
|
-
enabled = isEnabled;
|
|
235
|
+
function enableTracking(enable) {
|
|
236
|
+
enabled = isEnabled() && enable;
|
|
239
237
|
}
|
|
240
238
|
function generateAnonymousId() {
|
|
241
239
|
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