apps-sdk 1.1.4 → 1.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -24,6 +24,22 @@ class MixPanel {
24
24
  }
25
25
  }
26
26
 
27
+ async getDistinctID() {
28
+ if (!this.mixpanel) {
29
+ console.log('Mixpanel is not initialized');
30
+ return null;
31
+ }
32
+
33
+ try {
34
+ const distinctId = await this.mixpanel.getDistinctId();
35
+ console.log('Current distinct ID:', distinctId);
36
+ return distinctId;
37
+ } catch (error) {
38
+ console.error('Error getting distinct ID:', error);
39
+ return null;
40
+ }
41
+ }
42
+
27
43
  async trackEvent(eventName, properties = {}) {
28
44
  if (!this.mixpanel) {
29
45
  console.log('Mixpanel is not initialized');
@@ -63,9 +79,12 @@ class MixPanel {
63
79
 
64
80
  try {
65
81
  if (!this.devMode) {
66
- if (config.TRACKING_ACTIVE) {
67
- await this.mixpanel.registerSuperProperties(properties);
68
- config.DEBUG_MODE && console.log('MixPanel Super Properties registered:', properties);
82
+ const trackingPermissionAnswered = await Storage.getData('TRACKING_PERMISSION_ANSWERED');
83
+ if (config.TRACKING_ACTIVE || !trackingPermissionAnswered) {
84
+ const distinctId = await this.getDistinctID();
85
+ const superProperties = { ...properties, distinct_id: distinctId };
86
+ await this.mixpanel.registerSuperProperties(superProperties);
87
+ config.DEBUG_MODE && console.log('MixPanel Super Properties registered:', superProperties);
69
88
  } else {
70
89
  config.DEBUG_MODE && console.log('MixPanel Super Properties not registered due to tracking permission:', properties);
71
90
  }
@@ -85,8 +104,10 @@ class MixPanel {
85
104
 
86
105
  try {
87
106
  if (!this.devMode) {
88
- await this.mixpanel.registerSuperPropertiesOnce(properties);
89
- config.DEBUG_MODE && console.log('MixPanel Super Properties appended:', properties);
107
+ const distinctId = await this.getDistinctID();
108
+ const superProperties = { ...properties, distinct_id: distinctId };
109
+ await this.mixpanel.registerSuperPropertiesOnce(superProperties);
110
+ config.DEBUG_MODE && console.log('MixPanel Super Properties appended:', superProperties);
90
111
  } else {
91
112
  config.DEBUG_MODE && console.log('MixPanel Super Properties appended but not send (DEV_MODE ON):', properties);
92
113
  }
@@ -121,8 +142,10 @@ class MixPanel {
121
142
 
122
143
  try {
123
144
  if (!this.devMode) {
124
- await this.mixpanel.getPeople().set(propertyName, propertyValue);
125
- config.DEBUG_MODE && console.log(`MixPanel User property set: ${propertyName} = ${propertyValue}`);
145
+ const distinctId = await this.getDistinctID();
146
+ const userProperties = { [propertyName]: propertyValue, distinct_id: distinctId };
147
+ await this.mixpanel.getPeople().set(userProperties);
148
+ config.DEBUG_MODE && console.log(`MixPanel User property set: ${propertyName} = ${propertyValue}, distinct_id = ${distinctId}`);
126
149
  } else {
127
150
  config.DEBUG_MODE && console.log(`MixPanel User property set but not send (DEV_MODE ON): ${propertyName} = ${propertyValue}`);
128
151
  }
package/types/index.d.ts CHANGED
@@ -181,6 +181,7 @@ declare module 'apps-sdk' {
181
181
 
182
182
  export class MixPanel {
183
183
  initialize(token?: string, trackAutomaticEvents?: boolean, useNative?: boolean, devMode?: boolean): Promise<void>;
184
+ getDistinctID(): Promise<string>;
184
185
  trackEvent(event: string, properties?: object): Promise<void>;
185
186
  trackEventIfExist(eventKeyword: string, eventData?: object): Promise<void>;
186
187
  isMixpanelInitialized(): boolean;