@armco/analytics 0.1.1 → 0.1.2
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 +2 -1
- package/dist/analytics.js +13 -3
- package/package.json +1 -1
package/dist/analytics.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { startSession, getSessionId } from "./session";
|
|
|
2
2
|
import { User, Event } from "./index.d";
|
|
3
3
|
declare let enabled: boolean | null;
|
|
4
4
|
declare function loadConfiguration(): Promise<any>;
|
|
5
|
+
declare function getEnvironment(): string;
|
|
5
6
|
declare function getEnvironmentType(): 'browser' | 'node' | 'unknown';
|
|
6
7
|
export declare function sendBulkData(data: Event[], callback?: Function): Promise<void>;
|
|
7
8
|
declare function trackEvent(event: string | Event, data?: any): void;
|
|
@@ -15,4 +16,4 @@ declare function identify(appUser: User): void;
|
|
|
15
16
|
declare function sendHostProjectName(): void;
|
|
16
17
|
declare function init(): void;
|
|
17
18
|
declare function logout(): void;
|
|
18
|
-
export { enabled as analyticsEnabled, init, identify, getEnvironmentType, loadConfiguration, logout, trackEvent, trackPageView, trackError, enableTracking, generateAnonymousId, sendHostProjectName, getSessionId, startSession, };
|
|
19
|
+
export { enabled as analyticsEnabled, init, identify, getEnvironmentType, getEnvironment, loadConfiguration, logout, trackEvent, trackPageView, trackError, enableTracking, generateAnonymousId, sendHostProjectName, getSessionId, startSession, };
|
package/dist/analytics.js
CHANGED
|
@@ -28,6 +28,7 @@ const CONFIG_FILE_NAME = "analyticsrc";
|
|
|
28
28
|
let region;
|
|
29
29
|
let address;
|
|
30
30
|
let coordinates;
|
|
31
|
+
let runtime = null;
|
|
31
32
|
let CONFIG;
|
|
32
33
|
let environment;
|
|
33
34
|
function isTypeScriptProject() {
|
|
@@ -66,7 +67,7 @@ function isTypeScriptProject() {
|
|
|
66
67
|
}
|
|
67
68
|
function loadConfiguration() {
|
|
68
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
const ROOT = "../../../../";
|
|
70
|
+
const ROOT = (runtime || getEnvironment()) === "production" ? "../../" : "../../../../";
|
|
70
71
|
let configFilePath = `${ROOT}${CONFIG_FILE_NAME}.json`;
|
|
71
72
|
try {
|
|
72
73
|
const config = yield import(configFilePath);
|
|
@@ -89,6 +90,15 @@ function loadConfiguration() {
|
|
|
89
90
|
return null;
|
|
90
91
|
});
|
|
91
92
|
}
|
|
93
|
+
function getEnvironment() {
|
|
94
|
+
if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV) {
|
|
95
|
+
return process.env.NODE_ENV;
|
|
96
|
+
}
|
|
97
|
+
if (import.meta.env && import.meta.env.MODE) {
|
|
98
|
+
return import.meta.env.MODE;
|
|
99
|
+
}
|
|
100
|
+
return 'development';
|
|
101
|
+
}
|
|
92
102
|
function getEnvironmentType() {
|
|
93
103
|
if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {
|
|
94
104
|
return 'browser';
|
|
@@ -379,8 +389,8 @@ function showTrackingPopup() {
|
|
|
379
389
|
function init() {
|
|
380
390
|
try {
|
|
381
391
|
environment = getEnvironmentType();
|
|
392
|
+
runtime = getEnvironment();
|
|
382
393
|
console.log("[ANALYTICS] Loading Configuration");
|
|
383
|
-
console.log("[ANALYTICS] Environment: ", import.meta.env.MODE);
|
|
384
394
|
loadConfiguration()
|
|
385
395
|
.then((config) => __awaiter(this, void 0, void 0, function* () {
|
|
386
396
|
CONFIG = config;
|
|
@@ -422,4 +432,4 @@ function logout() {
|
|
|
422
432
|
}
|
|
423
433
|
terminateSession();
|
|
424
434
|
}
|
|
425
|
-
export { enabled as analyticsEnabled, init, identify, getEnvironmentType, loadConfiguration, logout, trackEvent, trackPageView, trackError, enableTracking, generateAnonymousId, sendHostProjectName, getSessionId, startSession, };
|
|
435
|
+
export { enabled as analyticsEnabled, init, identify, getEnvironmentType, getEnvironment, loadConfiguration, logout, trackEvent, trackPageView, trackError, enableTracking, generateAnonymousId, sendHostProjectName, getSessionId, startSession, };
|