@pushwoosh/kit-helpers 4.8.7 → 4.8.9

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 +1,2 @@
1
- export declare const identifyMixpanel: (email: string) => void;
1
+ import { type MixpanelProperties } from './utils';
2
+ export declare const identifyMixpanel: (properties: MixpanelProperties) => void;
@@ -1,16 +1,17 @@
1
- import { isProductionMode, isUserActionsTrackingOff } from './utils';
2
- export const identifyMixpanel = email => {
3
- if (!isProductionMode() || isUserActionsTrackingOff()) {
1
+ import { isProductionMode, isUserActionsTrackingOff, getMixpanelDistinctId } from './utils';
2
+ export const identifyMixpanel = properties => {
3
+ const distinctId = getMixpanelDistinctId();
4
+ const wasPushwooshUser = distinctId?.endsWith('@pushwoosh.com');
5
+ const isCurrentPushwooshUser = properties.$email.endsWith('@pushwoosh.com');
6
+ if (!isProductionMode() || isUserActionsTrackingOff() || wasPushwooshUser || isCurrentPushwooshUser) {
4
7
  return;
5
8
  }
6
9
  if (!window.mixpanel) {
7
10
  const store = window.pwMixpanelIdentifyStore || [];
8
- store.push(email);
11
+ store.push(properties);
9
12
  window.pwMixpanelIdentifyStore = store;
10
13
  } else {
11
- window.mixpanel?.identify(email);
12
- window.mixpanel?.people?.set({
13
- $email: email
14
- });
14
+ window.mixpanel?.identify(properties?.$email);
15
+ window.mixpanel?.people?.set(properties);
15
16
  }
16
17
  };
@@ -1 +1,2 @@
1
- export declare const identifyOpenReplaySession: (email: string) => void;
1
+ import { type OpenReplayProperties } from './utils';
2
+ export declare const identifyOpenReplaySession: (properties: OpenReplayProperties) => void;
@@ -1,13 +1,16 @@
1
1
  import { isProductionMode, isUserActionsTrackingOff } from './utils';
2
- export const identifyOpenReplaySession = email => {
2
+ export const identifyOpenReplaySession = properties => {
3
3
  if (!isProductionMode() || isUserActionsTrackingOff()) {
4
4
  return;
5
5
  }
6
6
  if (!window.OpenReplay) {
7
7
  const store = window.pwOpenReplayIdentifyStore || [];
8
- store.push(email);
8
+ store.push(properties);
9
9
  window.pwOpenReplayIdentifyStore = store;
10
10
  } else {
11
- window.OpenReplay?.setUserID(email);
11
+ window.OpenReplay?.setUserID(properties.email);
12
+ if (properties.accountID) {
13
+ window.OpenReplay?.setMetadata('AccountID', `${properties.accountID}`);
14
+ }
12
15
  }
13
16
  };
@@ -1,20 +1,32 @@
1
1
  import { type Mixpanel } from 'mixpanel-browser';
2
2
  interface IOpenReplay {
3
3
  setUserID(id: string): void;
4
+ setMetadata(key: string, value: string): void;
4
5
  }
5
6
  export type Event = {
6
7
  readonly name: string;
7
8
  readonly properties?: Record<string, unknown>;
8
9
  };
10
+ export type MixpanelProperties = {
11
+ $email: string;
12
+ $name?: string;
13
+ AccountID?: string;
14
+ Restriction?: string;
15
+ };
16
+ export type OpenReplayProperties = {
17
+ email: string;
18
+ accountID?: string;
19
+ };
9
20
  declare global {
10
21
  interface Window {
11
22
  mixpanel?: Mixpanel;
12
23
  OpenReplay?: IOpenReplay;
13
- pwMixpanelIdentifyStore?: string[];
14
- pwOpenReplayIdentifyStore?: string[];
24
+ pwMixpanelIdentifyStore?: MixpanelProperties[];
25
+ pwOpenReplayIdentifyStore?: OpenReplayProperties[];
15
26
  pwMixpanelTrackingEventsStore?: Event[];
16
27
  }
17
28
  }
18
29
  export declare const isProductionMode: () => boolean;
19
30
  export declare const isUserActionsTrackingOff: () => boolean;
31
+ export declare const getMixpanelDistinctId: () => string | null;
20
32
  export {};
@@ -1,7 +1,21 @@
1
+ import Cookies from 'js-cookie';
1
2
  export const isProductionMode = () => process.env.NODE_ENV === 'production';
2
3
  export const isUserActionsTrackingOff = () => {
3
4
  const turnOffTracking = localStorage.getItem('pw_off_user_actions_tracking');
4
5
  // Any value other than these specific "falsey" ones means tracking is off.
5
6
  const trackingOnValues = [null, '', '0', 'false'];
6
7
  return !trackingOnValues.includes(turnOffTracking);
8
+ };
9
+ const projectToken = '4169a4e38679ed49785b430a1049238e';
10
+ export const getMixpanelDistinctId = () => {
11
+ const mixpanelCookie = Cookies.get(`mp_${projectToken}_mixpanel`);
12
+ if (mixpanelCookie) {
13
+ try {
14
+ const mixpanelData = JSON.parse(mixpanelCookie);
15
+ return mixpanelData.distinct_id;
16
+ } catch (error) {
17
+ console.error('Error parsing Mixpanel cookie:', error);
18
+ }
19
+ }
20
+ return null;
7
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/kit-helpers",
3
- "version": "4.8.7",
3
+ "version": "4.8.9",
4
4
  "description": "React component for build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -16,12 +16,14 @@
16
16
  },
17
17
  "pre-commit": "check",
18
18
  "dependencies": {
19
+ "js-cookie": "^3.0.5",
19
20
  "mixpanel-browser": "^2.71.0",
20
21
  "react-transition-group": "^4.4.5"
21
22
  },
22
23
  "devDependencies": {
23
24
  "@pushwoosh/frontend-builder-engine": "^0.1.5",
24
25
  "@pushwoosh/kit-constants": "^1.6.0",
26
+ "@types/js-cookie": "^3.0.6",
25
27
  "@types/react": "^16.14.20",
26
28
  "@types/react-dom": "^16.9.14",
27
29
  "@types/react-transition-group": "^4.4.10",