@workleap/mixpanel 2.1.6 → 2.1.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @workleap/mixpanel
2
2
 
3
+ ## 2.1.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [#72](https://github.com/workleap/wl-telemetry/pull/72) [`baf14c4`](https://github.com/workleap/wl-telemetry/commit/baf14c474e4cac0eab8fa15bf3986c4f27f40342) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Added a global variables indicating that Mixpanel has been initialized.
8
+
3
9
  ## 2.1.6
4
10
 
5
11
  ### Patch Changes
@@ -1,5 +1,6 @@
1
1
  import { type RootLogger } from "@workleap/logging";
2
2
  import { type Environment } from "./env.ts";
3
+ export declare const IsInitializedVariableName = "__WLP_MIXPANEL_IS_INITIALIZED__";
3
4
  /**
4
5
  * @see {@link https://workleap.github.io/wl-telemetry}
5
6
  */
@@ -24,6 +24,7 @@ import { OtherProperties, getSuperProperties, getTelemetryProperties, setSuperPr
24
24
 
25
25
 
26
26
 
27
+ const IsInitializedVariableName = "__WLP_MIXPANEL_IS_INITIALIZED__";
27
28
  function registerLogRocketSessionUrlListener(logger) {
28
29
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
29
30
  // @ts-ignore
@@ -77,9 +78,15 @@ function __resetInitializationGuard() {
77
78
  superProperties: getSuperProperties(),
78
79
  logger
79
80
  });
81
+ // Indicates to the host applications that Mixpanel has been initialized.
82
+ // It's useful in cases where an "add-on", like the platform widgets needs
83
+ // to know whether or not the host application is using Mixpanel.
84
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
85
+ // @ts-ignore
86
+ globalThis[IsInitializedVariableName] = true;
80
87
  logger.information("[mixpanel] Mixpanel is initialized.");
81
88
  }
82
89
 
83
- export { __resetInitializationGuard, initializeMixpanel };
90
+ export { IsInitializedVariableName, __resetInitializationGuard, initializeMixpanel };
84
91
 
85
92
  //# sourceMappingURL=initializeMixpanel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"js/initializeMixpanel.js","sources":["webpack://@workleap/mixpanel/./src/js/initializeMixpanel.ts"],"sourcesContent":["import { createCompositeLogger, type Logger, type RootLogger } from \"@workleap/logging\";\nimport { createBootstrappingStore, createTelemetryContext } from \"@workleap/telemetry\";\nimport { setMixpanelContext } from \"./context.ts\";\nimport { getTrackingEndpoint, type Environment } from \"./env.ts\";\nimport { HasExecutedGuard } from \"./HasExecutedGuard.ts\";\nimport { getSuperProperties, getTelemetryProperties, OtherProperties, setSuperProperties, setSuperProperty } from \"./properties.ts\";\n\n/**\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport interface InitializeMixpanelOptions {\n /**\n * An optional tracking endpoint.\n * @default \"tracking/track\"\n */\n trackingEndpoint?: string;\n /**\n * Whether or not debug information should be logged to the console.\n */\n verbose?: boolean;\n /**\n * An array of RootLogger instances.\n */\n loggers?: RootLogger[];\n}\n\nfunction registerLogRocketSessionUrlListener(logger: Logger) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__) {\n // Automatically add the LogRocket session URL to all Honeycomb traces as an attribute.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__((sessionUrl: string) => {\n logger\n .withText(\"[mixpanel] Received LogRocket session replay URL:\")\n .withText(sessionUrl)\n .debug();\n\n setSuperProperty(OtherProperties.LogRocketSessionUrl, sessionUrl);\n });\n } else {\n logger.information(\"[mixpanel] Cannot integrate with LogRocket because \\\"globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__\\\" is not available.\");\n }\n}\n\nconst initializationGuard = new HasExecutedGuard();\n\n// This function should only be used by tests.\nexport function __resetInitializationGuard() {\n initializationGuard.reset();\n}\n\n/**\n * Creates a function that sends tracking events to the tracking API.\n * @param productId Your product identifier.\n * @param envOrTrackingApiBaseUrl The environment to get the navigation url from or a base URL.\n * @param options Options for creating the tracking function.\n * @returns A function that sends tracking events to the tracking API.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport function initializeMixpanel(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), options: InitializeMixpanelOptions = {}) {\n const {\n trackingEndpoint,\n verbose = false,\n loggers = []\n } = options;\n\n initializationGuard.throw(\"[mixpanel] Mixpanel has already been initialized. Did you call the \\\"initializeMixpanel\\\" function twice?\");\n\n const logger = createCompositeLogger(verbose, loggers);\n const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl, trackingEndpoint);\n const telemetryContext = createTelemetryContext(logger);\n\n setSuperProperties(getTelemetryProperties(telemetryContext));\n\n const bootstrappingStore = createBootstrappingStore(logger);\n\n // If LogRocket is already available, register the listener. Otherwise, subscribe to the bootstrapping store\n // and register the listener once a notification is received that LogRocket is registered.\n if (bootstrappingStore.state.isLogRocketReady) {\n registerLogRocketSessionUrlListener(logger);\n } else {\n bootstrappingStore.subscribe((action, store, unsubscribe) => {\n if (store.state.isLogRocketReady) {\n unsubscribe();\n registerLogRocketSessionUrlListener(logger);\n }\n });\n }\n\n setMixpanelContext({\n productId,\n endpoint,\n superProperties: getSuperProperties(),\n logger\n });\n\n logger.information(\"[mixpanel] Mixpanel is initialized.\");\n}\n"],"names":["createCompositeLogger","createBootstrappingStore","createTelemetryContext","setMixpanelContext","getTrackingEndpoint","HasExecutedGuard","getSuperProperties","getTelemetryProperties","OtherProperties","setSuperProperties","setSuperProperty","registerLogRocketSessionUrlListener","logger","globalThis","sessionUrl","initializationGuard","__resetInitializationGuard","initializeMixpanel","productId","envOrTrackingApiBaseUrl","options","trackingEndpoint","verbose","loggers","endpoint","telemetryContext","bootstrappingStore","action","store","unsubscribe"],"mappings":";;;;;;;;;;;;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"file":"js/initializeMixpanel.js","sources":["webpack://@workleap/mixpanel/./src/js/initializeMixpanel.ts"],"sourcesContent":["import { createCompositeLogger, type Logger, type RootLogger } from \"@workleap/logging\";\nimport { createBootstrappingStore, createTelemetryContext } from \"@workleap/telemetry\";\nimport { setMixpanelContext } from \"./context.ts\";\nimport { getTrackingEndpoint, type Environment } from \"./env.ts\";\nimport { HasExecutedGuard } from \"./HasExecutedGuard.ts\";\nimport { getSuperProperties, getTelemetryProperties, OtherProperties, setSuperProperties, setSuperProperty } from \"./properties.ts\";\n\nexport const IsInitializedVariableName = \"__WLP_MIXPANEL_IS_INITIALIZED__\";\n\n/**\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport interface InitializeMixpanelOptions {\n /**\n * An optional tracking endpoint.\n * @default \"tracking/track\"\n */\n trackingEndpoint?: string;\n /**\n * Whether or not debug information should be logged to the console.\n */\n verbose?: boolean;\n /**\n * An array of RootLogger instances.\n */\n loggers?: RootLogger[];\n}\n\nfunction registerLogRocketSessionUrlListener(logger: Logger) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__) {\n // Automatically add the LogRocket session URL to all Honeycomb traces as an attribute.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__((sessionUrl: string) => {\n logger\n .withText(\"[mixpanel] Received LogRocket session replay URL:\")\n .withText(sessionUrl)\n .debug();\n\n setSuperProperty(OtherProperties.LogRocketSessionUrl, sessionUrl);\n });\n } else {\n logger.information(\"[mixpanel] Cannot integrate with LogRocket because \\\"globalThis.__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__\\\" is not available.\");\n }\n}\n\nconst initializationGuard = new HasExecutedGuard();\n\n// This function should only be used by tests.\nexport function __resetInitializationGuard() {\n initializationGuard.reset();\n}\n\n/**\n * Creates a function that sends tracking events to the tracking API.\n * @param productId Your product identifier.\n * @param envOrTrackingApiBaseUrl The environment to get the navigation url from or a base URL.\n * @param options Options for creating the tracking function.\n * @returns A function that sends tracking events to the tracking API.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport function initializeMixpanel(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), options: InitializeMixpanelOptions = {}) {\n const {\n trackingEndpoint,\n verbose = false,\n loggers = []\n } = options;\n\n initializationGuard.throw(\"[mixpanel] Mixpanel has already been initialized. Did you call the \\\"initializeMixpanel\\\" function twice?\");\n\n const logger = createCompositeLogger(verbose, loggers);\n const endpoint = getTrackingEndpoint(envOrTrackingApiBaseUrl, trackingEndpoint);\n const telemetryContext = createTelemetryContext(logger);\n\n setSuperProperties(getTelemetryProperties(telemetryContext));\n\n const bootstrappingStore = createBootstrappingStore(logger);\n\n // If LogRocket is already available, register the listener. Otherwise, subscribe to the bootstrapping store\n // and register the listener once a notification is received that LogRocket is registered.\n if (bootstrappingStore.state.isLogRocketReady) {\n registerLogRocketSessionUrlListener(logger);\n } else {\n bootstrappingStore.subscribe((action, store, unsubscribe) => {\n if (store.state.isLogRocketReady) {\n unsubscribe();\n registerLogRocketSessionUrlListener(logger);\n }\n });\n }\n\n setMixpanelContext({\n productId,\n endpoint,\n superProperties: getSuperProperties(),\n logger\n });\n\n // Indicates to the host applications that Mixpanel has been initialized.\n // It's useful in cases where an \"add-on\", like the platform widgets needs\n // to know whether or not the host application is using Mixpanel.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n globalThis[IsInitializedVariableName] = true;\n\n logger.information(\"[mixpanel] Mixpanel is initialized.\");\n}\n"],"names":["createCompositeLogger","createBootstrappingStore","createTelemetryContext","setMixpanelContext","getTrackingEndpoint","HasExecutedGuard","getSuperProperties","getTelemetryProperties","OtherProperties","setSuperProperties","setSuperProperty","IsInitializedVariableName","registerLogRocketSessionUrlListener","logger","globalThis","sessionUrl","initializationGuard","__resetInitializationGuard","initializeMixpanel","productId","envOrTrackingApiBaseUrl","options","trackingEndpoint","verbose","loggers","endpoint","telemetryContext","bootstrappingStore","action","store","unsubscribe"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAwF;AACD;AACrC;AACe;AACR;AAC2E;AAE7H,MAAMW,4BAA4B,kCAAkC;AAqB3E,SAASC,oCAAoCC,MAAc;IACvD,6DAA6D;IAC7D,aAAa;IACb,IAAIC,WAAW,mEAAmE,EAAE;QAChF,uFAAuF;QACvF,6DAA6D;QAC7D,aAAa;QACbA,WAAW,mEAAmE,CAAC,CAACC;YAC5EF,OACK,QAAQ,CAAC,qDACT,QAAQ,CAACE,YACT,KAAK;YAEVL,gBAAgBA,CAACF,mCAAmC,EAAEO;QAC1D;IACJ,OAAO;QACHF,OAAO,WAAW,CAAC;IACvB;AACJ;AAEA,MAAMG,sBAAsB,IAAIX,gBAAgBA;AAEhD,8CAA8C;AACvC,SAASY;IACZD,oBAAoB,KAAK;AAC7B;AAEA;;;;;;;CAOC,GACM,SAASE,mBAAmBC,SAAiB,EAAEC,uBAAoD,EAAEC,UAAqC,CAAC,CAAC;IAC/I,MAAM,EACFC,gBAAgB,EAChBC,UAAU,KAAK,EACfC,UAAU,EAAE,EACf,GAAGH;IAEJL,oBAAoB,KAAK,CAAC;IAE1B,MAAMH,SAASb,qBAAqBA,CAACuB,SAASC;IAC9C,MAAMC,WAAWrB,mBAAmBA,CAACgB,yBAAyBE;IAC9D,MAAMI,mBAAmBxB,sBAAsBA,CAACW;IAEhDJ,kBAAkBA,CAACF,sBAAsBA,CAACmB;IAE1C,MAAMC,qBAAqB1B,wBAAwBA,CAACY;IAEpD,4GAA4G;IAC5G,0FAA0F;IAC1F,IAAIc,mBAAmB,KAAK,CAAC,gBAAgB,EAAE;QAC3Cf,oCAAoCC;IACxC,OAAO;QACHc,mBAAmB,SAAS,CAAC,CAACC,QAAQC,OAAOC;YACzC,IAAID,MAAM,KAAK,CAAC,gBAAgB,EAAE;gBAC9BC;gBACAlB,oCAAoCC;YACxC;QACJ;IACJ;IAEAV,kBAAkBA,CAAC;QACfgB;QACAM;QACA,iBAAiBnB,kBAAkBA;QACnCO;IACJ;IAEA,yEAAyE;IACzE,0EAA0E;IAC1E,iEAAiE;IACjE,6DAA6D;IAC7D,aAAa;IACbC,UAAU,CAACH,0BAA0B,GAAG;IAExCE,OAAO,WAAW,CAAC;AACvB"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@workleap/mixpanel",
3
3
  "author": "Workleap",
4
- "version": "2.1.6",
4
+ "version": "2.1.7",
5
5
  "description": "A package containing utilities for Mixpanel telemetry.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -5,6 +5,8 @@ import { getTrackingEndpoint, type Environment } from "./env.ts";
5
5
  import { HasExecutedGuard } from "./HasExecutedGuard.ts";
6
6
  import { getSuperProperties, getTelemetryProperties, OtherProperties, setSuperProperties, setSuperProperty } from "./properties.ts";
7
7
 
8
+ export const IsInitializedVariableName = "__WLP_MIXPANEL_IS_INITIALIZED__";
9
+
8
10
  /**
9
11
  * @see {@link https://workleap.github.io/wl-telemetry}
10
12
  */
@@ -96,5 +98,12 @@ export function initializeMixpanel(productId: string, envOrTrackingApiBaseUrl: E
96
98
  logger
97
99
  });
98
100
 
101
+ // Indicates to the host applications that Mixpanel has been initialized.
102
+ // It's useful in cases where an "add-on", like the platform widgets needs
103
+ // to know whether or not the host application is using Mixpanel.
104
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
105
+ // @ts-ignore
106
+ globalThis[IsInitializedVariableName] = true;
107
+
99
108
  logger.information("[mixpanel] Mixpanel is initialized.");
100
109
  }