@armco/analytics 0.0.4 → 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 +9 -8
- 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,10 +198,6 @@ 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;
|
|
@@ -225,13 +225,14 @@ function isEnabled() {
|
|
|
225
225
|
if (typeof navigator !== 'undefined' && 'doNotTrack' in navigator) {
|
|
226
226
|
const doNotTrackValue = navigator.doNotTrack;
|
|
227
227
|
if (doNotTrackValue === '1' || doNotTrackValue === 'yes') {
|
|
228
|
-
|
|
228
|
+
console.warn("[ANALYTICS] Tracking disabled in client, events will not be logged!");
|
|
229
|
+
return isArClient(hostProjectName) || false;
|
|
229
230
|
}
|
|
230
231
|
}
|
|
231
232
|
return true;
|
|
232
233
|
}
|
|
233
|
-
function enableTracking(
|
|
234
|
-
enabled = isEnabled;
|
|
234
|
+
function enableTracking(enable) {
|
|
235
|
+
enabled = isEnabled() && enable;
|
|
235
236
|
}
|
|
236
237
|
function generateAnonymousId() {
|
|
237
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