@armco/analytics 0.1.0 → 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.
@@ -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';
@@ -377,11 +387,10 @@ function showTrackingPopup() {
377
387
  });
378
388
  }
379
389
  function init() {
380
- var _a;
381
390
  try {
382
391
  environment = getEnvironmentType();
392
+ runtime = getEnvironment();
383
393
  console.log("[ANALYTICS] Loading Configuration");
384
- console.log("[ANALYTICS] Environment: ", (_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV);
385
394
  loadConfiguration()
386
395
  .then((config) => __awaiter(this, void 0, void 0, function* () {
387
396
  CONFIG = config;
@@ -423,4 +432,4 @@ function logout() {
423
432
  }
424
433
  terminateSession();
425
434
  }
426
- 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, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armco/analytics",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Browser Based Analytics interceptor for configured events",
5
5
  "main": "index.js",
6
6
  "type": "module",