@armco/analytics 0.1.2 → 0.1.3

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,13 @@
1
1
  import { startSession, getSessionId } from "./session";
2
- import { User, Event } from "./index.d";
2
+ import { User, Event, SubmissionStrategy } from "./index.d";
3
+ interface ConfigType {
4
+ apiKey?: string;
5
+ analyticsEndpoint?: string;
6
+ hostProjectName?: string;
7
+ trackEvents?: Array<string>;
8
+ submissionStrategy?: SubmissionStrategy;
9
+ showPopUp?: boolean;
10
+ }
3
11
  declare let enabled: boolean | null;
4
12
  declare function loadConfiguration(): Promise<any>;
5
13
  declare function getEnvironment(): string;
@@ -14,6 +22,6 @@ declare function enableTracking(enable: boolean): void;
14
22
  declare function generateAnonymousId(): string;
15
23
  declare function identify(appUser: User): void;
16
24
  declare function sendHostProjectName(): void;
17
- declare function init(): void;
25
+ declare function init(config?: ConfigType): void;
18
26
  declare function logout(): void;
19
27
  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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armco/analytics",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Browser Based Analytics interceptor for configured events",
5
5
  "main": "index.js",
6
6
  "type": "module",