@pushwoosh/kit-helpers 4.8.6 → 4.8.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.
@@ -0,0 +1 @@
1
+ export declare const identifyMixpanel: (email: string) => void;
@@ -0,0 +1,16 @@
1
+ import { isProductionMode, isUserActionsTrackingOff } from './utils';
2
+ export const identifyMixpanel = email => {
3
+ if (!isProductionMode() || isUserActionsTrackingOff()) {
4
+ return;
5
+ }
6
+ if (!window.mixpanel) {
7
+ const store = window.pwMixpanelIdentifyStore || [];
8
+ store.push(email);
9
+ window.pwMixpanelIdentifyStore = store;
10
+ } else {
11
+ window.mixpanel?.identify(email);
12
+ window.mixpanel?.people?.set({
13
+ $email: email
14
+ });
15
+ }
16
+ };
@@ -0,0 +1 @@
1
+ export declare const identifyOpenReplaySession: (email: string) => void;
@@ -0,0 +1,13 @@
1
+ import { isProductionMode, isUserActionsTrackingOff } from './utils';
2
+ export const identifyOpenReplaySession = email => {
3
+ if (!isProductionMode() || isUserActionsTrackingOff()) {
4
+ return;
5
+ }
6
+ if (!window.OpenReplay) {
7
+ const store = window.pwOpenReplayIdentifyStore || [];
8
+ store.push(email);
9
+ window.pwOpenReplayIdentifyStore = store;
10
+ } else {
11
+ window.OpenReplay?.setUserID(email);
12
+ }
13
+ };
@@ -0,0 +1,2 @@
1
+ import { type Event } from './utils';
2
+ export declare function trackMixpanelEvent(event: Event): void;
@@ -0,0 +1,13 @@
1
+ import { isProductionMode, isUserActionsTrackingOff } from './utils';
2
+ export function trackMixpanelEvent(event) {
3
+ if (!isProductionMode() || isUserActionsTrackingOff()) {
4
+ return;
5
+ }
6
+ if (!window.mixpanel) {
7
+ const store = window.pwMixpanelTrackingEventsStore || [];
8
+ store.push(event);
9
+ window.pwMixpanelTrackingEventsStore = store;
10
+ } else {
11
+ window.mixpanel?.track(event.name, event.properties);
12
+ }
13
+ }
@@ -0,0 +1,20 @@
1
+ import { type Mixpanel } from 'mixpanel-browser';
2
+ interface IOpenReplay {
3
+ setUserID(id: string): void;
4
+ }
5
+ export type Event = {
6
+ readonly name: string;
7
+ readonly properties?: Record<string, unknown>;
8
+ };
9
+ declare global {
10
+ interface Window {
11
+ mixpanel?: Mixpanel;
12
+ OpenReplay?: IOpenReplay;
13
+ pwMixpanelIdentifyStore?: string[];
14
+ pwOpenReplayIdentifyStore?: string[];
15
+ pwMixpanelTrackingEventsStore?: Event[];
16
+ }
17
+ }
18
+ export declare const isProductionMode: () => boolean;
19
+ export declare const isUserActionsTrackingOff: () => boolean;
20
+ export {};
@@ -0,0 +1,7 @@
1
+ export const isProductionMode = () => process.env.NODE_ENV === 'production';
2
+ export const isUserActionsTrackingOff = () => {
3
+ const turnOffTracking = localStorage.getItem('pw_off_user_actions_tracking');
4
+ // Any value other than these specific "falsey" ones means tracking is off.
5
+ const trackingOnValues = [null, '', '0', 'false'];
6
+ return !trackingOnValues.includes(turnOffTracking);
7
+ };
package/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export * from './grid';
2
2
  export * from './expand';
3
3
  export * from './hooks/useClickAway';
4
+ export { trackMixpanelEvent } from './analytics/trackMixpanel';
5
+ export { identifyMixpanel } from './analytics/identifyMixpanel';
6
+ export { identifyOpenReplaySession } from './analytics/identifyOpenReplay';
4
7
  export { formatNumber } from './formatNumber';
5
8
  export { default as usePersistentFunction } from './hooks/usePersistentFunction';
6
9
  export { default as useEffectOnce } from './hooks/useEffectOnce';
package/index.js CHANGED
@@ -1,6 +1,9 @@
1
1
  export * from './grid';
2
2
  export * from './expand';
3
3
  export * from './hooks/useClickAway';
4
+ export { trackMixpanelEvent } from './analytics/trackMixpanel';
5
+ export { identifyMixpanel } from './analytics/identifyMixpanel';
6
+ export { identifyOpenReplaySession } from './analytics/identifyOpenReplay';
4
7
  export { formatNumber } from './formatNumber';
5
8
  export { default as usePersistentFunction } from './hooks/usePersistentFunction';
6
9
  export { default as useEffectOnce } from './hooks/useEffectOnce';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/kit-helpers",
3
- "version": "4.8.6",
3
+ "version": "4.8.7",
4
4
  "description": "React component for build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -16,6 +16,7 @@
16
16
  },
17
17
  "pre-commit": "check",
18
18
  "dependencies": {
19
+ "mixpanel-browser": "^2.71.0",
19
20
  "react-transition-group": "^4.4.5"
20
21
  },
21
22
  "devDependencies": {