@armco/analytics 0.1.2 → 0.1.4

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.
@@ -1,5 +1,5 @@
1
1
  import { startSession, getSessionId } from "./session";
2
- import { User, Event } from "./index.d";
2
+ import { User, Event, ConfigType } from "./index.d";
3
3
  declare let enabled: boolean | null;
4
4
  declare function loadConfiguration(): Promise<any>;
5
5
  declare function getEnvironment(): string;
@@ -14,6 +14,6 @@ declare function enableTracking(enable: boolean): void;
14
14
  declare function generateAnonymousId(): string;
15
15
  declare function identify(appUser: User): void;
16
16
  declare function sendHostProjectName(): void;
17
- declare function init(): void;
17
+ declare function init(config?: ConfigType): void;
18
18
  declare function logout(): void;
19
19
  export { enabled as analyticsEnabled, init, identify, getEnvironmentType, getEnvironment, loadConfiguration, logout, trackEvent, trackPageView, trackError, enableTracking, generateAnonymousId, sendHostProjectName, getSessionId, startSession, };
package/dist/analytics.js CHANGED
@@ -386,40 +386,61 @@ function showTrackingPopup() {
386
386
  $('.tracking-popup').remove();
387
387
  });
388
388
  }
389
- function init() {
389
+ function loadAnalytics(config) {
390
+ console.log("[ANALYTICS] Loading Configuration");
391
+ CONFIG = config;
392
+ if (CONFIG) {
393
+ console.log("[ANALYTICS] Configuration loaded");
394
+ apiKey = CONFIG.apiKey || null;
395
+ analyticsEndpoint = CONFIG.analyticsEndpoint || null;
396
+ hostProjectName = CONFIG.hostProjectName || hostProjectName || null;
397
+ console.log("[ANALYTICS] Check if Analytics enabled");
398
+ enabled = isEnabled();
399
+ if (enabled) {
400
+ console.log("[ANALYTICS] Display Tracker Popup");
401
+ CONFIG.showPopUp && showTrackingPopup();
402
+ console.log("[ANALYTICS] Hook Event Trackers");
403
+ hookTrackers();
404
+ console.log("[ANALYTICS] Hook Handlers to flush events (use when submissionStrategy is configured as \"DEFER\"");
405
+ hookFlushHandlers(CONFIG.submissionStrategy);
406
+ console.log("[ANALYTICS] Find User Location Details");
407
+ populateLocationDetails();
408
+ console.log("[ANALYTICS] Initiate Session and Anonymous User ID");
409
+ const anonId = generateAnonymousId();
410
+ console.log("Tracking User as", anonId);
411
+ startSession();
412
+ }
413
+ else {
414
+ console.warn("[ANALYTICS] Analytics blocked by client, or disabled by configuration!");
415
+ }
416
+ }
417
+ }
418
+ function init(config) {
390
419
  try {
391
420
  environment = getEnvironmentType();
392
421
  runtime = getEnvironment();
393
- console.log("[ANALYTICS] Loading Configuration");
394
- loadConfiguration()
395
- .then((config) => __awaiter(this, void 0, void 0, function* () {
396
- CONFIG = config;
397
- if (CONFIG) {
398
- console.log("[ANALYTICS] Configuration loaded");
399
- apiKey = CONFIG.apiKey || null;
400
- analyticsEndpoint = CONFIG.analyticsEndpoint || null;
401
- hostProjectName = CONFIG.hostProjectName || (yield getHostProjectName()) || null;
402
- console.log("[ANALYTICS] Check if Analytics enabled");
403
- enabled = isEnabled();
404
- if (enabled) {
405
- console.log("[ANALYTICS] Display Tracker Popup");
406
- CONFIG.showPopUp && showTrackingPopup();
407
- console.log("[ANALYTICS] Hook Event Trackers");
408
- hookTrackers();
409
- console.log("[ANALYTICS] Hook Handlers to flush events (use when submissionStrategy is configured as \"DEFER\"");
410
- hookFlushHandlers(CONFIG.submissionStrategy);
411
- console.log("[ANALYTICS] Find User Location Details");
412
- populateLocationDetails();
413
- console.log("[ANALYTICS] Initiate Session and Anonymous User ID");
414
- const anonId = generateAnonymousId();
415
- console.log("Tracking User as", anonId);
416
- startSession();
422
+ const projectName = config && config.hostProjectName;
423
+ if (projectName) {
424
+ hostProjectName = projectName;
425
+ }
426
+ else {
427
+ getHostProjectName()
428
+ .then((projectName) => {
429
+ hostProjectName = projectName;
430
+ if (config) {
431
+ loadAnalytics(config);
417
432
  }
418
433
  else {
419
- console.warn("[ANALYTICS] Analytics blocked by client, or disabled by configuration!");
434
+ loadConfiguration()
435
+ .then(config => {
436
+ loadAnalytics(config);
437
+ });
420
438
  }
421
- }
422
- }));
439
+ })
440
+ .catch((err) => {
441
+ console.error("[ANALYTICS] Couldn't determine host project name, no events will be logged!");
442
+ });
443
+ }
423
444
  }
424
445
  catch (e) {
425
446
  console.log("[ANALYTICS]", e);
package/index.d.ts CHANGED
@@ -1,24 +1,34 @@
1
1
  import main from "./dist";
2
2
 
3
3
  export interface User {
4
- email: string;
5
- // Other user properties...
4
+ email: string;
5
+ // Other user properties...
6
6
  }
7
7
 
8
8
  export interface Event {
9
- eventType: string;
10
- timestamp?: Date;
9
+ eventType: string;
10
+ timestamp?: Date;
11
11
  region?: string,
12
12
  address?: string,
13
13
  coordinates?: {
14
14
  latitude: number
15
15
  longitude: number
16
16
  }
17
- [key: string]: any; // Index signature to accept any other properties with their associated types
17
+ [key: string]: any; // Index signature to accept any other properties with their associated types
18
18
  }
19
19
 
20
- export type SubmissionStrategy = "ONEVENT" | "DEFER"
21
20
 
21
+ export interface ConfigType {
22
+ apiKey?: string;
23
+ analyticsEndpoint?: string;
24
+ hostProjectName?: string;
25
+ trackEvents?: Array<string>;
26
+ submissionStrategy?: SubmissionStrategy
27
+ showPopUp?: boolean
28
+ }
29
+
30
+ export type SubmissionStrategy = "ONEVENT" | "DEFER"
31
+ export type objType = { [key: string]: any }
22
32
  export type EVENT_TYPES = "CLICK" | "SUBMIT" | "SCROLL" | string
23
33
 
24
34
  export default main;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armco/analytics",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Browser Based Analytics interceptor for configured events",
5
5
  "main": "index.js",
6
6
  "type": "module",