@moengage/web-sdk 2.52.1 → 2.52.2

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/README.md CHANGED
@@ -24,11 +24,20 @@ moengage.initialize(
24
24
  }
25
25
  );
26
26
 
27
+ moengage.identifyUser({
28
+ uid: 'abc@xyz.com',
29
+ u_mb: '8989898989',
30
+ u_fn: 'some name',
31
+ });
27
32
 
28
- moengage.add_unique_user_id('abc@xyz.com');
29
- moengage.add_email('abc@xyz.com');
33
+ // don't use this and the above methods (identifyUser) together in your program. use only one of them.
34
+ moengage.add_unique_user_id('an_identifier');
30
35
 
31
- moengage.track_event('Add to Cart', {name: 'Phone', price: '100000'})
36
+ moengage.add_email('qwerty@xyz.com');
37
+
38
+ moengage.track_event('Add to Cart', { name: 'Phone', price: '100000' });
39
+
40
+ moengage.destroy_session();
32
41
 
33
42
  ```
34
43
 
package/dist/index.d.ts CHANGED
@@ -84,6 +84,10 @@ declare interface InitData {
84
84
  sdkVersion?: string;
85
85
  }
86
86
 
87
+ declare interface Identity {
88
+ [identity: string]: string;
89
+ }
90
+
87
91
  /**
88
92
  * Initializes the SDK.
89
93
  * @param initData - configuration for SDK intialization.
@@ -131,6 +135,26 @@ declare function add_unique_user_id(id: string | number): Promise<any>;
131
135
  */
132
136
  declare function update_unique_user_id(id: string | number): Promise<any>;
133
137
 
138
+ /**
139
+ * Adds/updates the identities of the user.
140
+ * @param identity - The identities associated to the user.
141
+ * @returns A promise that resolves when setting of the identities is complete.
142
+ */
143
+ declare function identifyUser(identity: Identity): Promise<any>;
144
+
145
+ /**
146
+ * Adds/updates the UID of the user.
147
+ * @param identity - The UID associated to the user.
148
+ * @returns A promise that resolves when setting of the UID is complete.
149
+ */
150
+ declare function identifyUser(identity: string): Promise<any>;
151
+
152
+ /**
153
+ * Provides the current identities associated to the user.
154
+ * @returns the current identities of the user or null, if no identities have been set.
155
+ */
156
+ declare function getUserIdentities(): Identity | null;
157
+
134
158
  /**
135
159
  * Adds a user attribute with the given name and value.
136
160
  * @param attrName - The name of the user attribute.
@@ -237,6 +261,8 @@ export {
237
261
  setDebugLevel,
238
262
  add_unique_user_id,
239
263
  update_unique_user_id,
264
+ identifyUser,
265
+ getUserIdentities,
240
266
  add_user_attribute,
241
267
  add_first_name,
242
268
  add_last_name,
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- const Moe={initialize:e=>{var a=e.app_id,o=e.debug_logs||0,n=e.cluster||"DC_1",d=e.disable_onsite||!1,i=e.enableSPA||!1,t=e.cards||null,s=e.disable_web_push||!1,r=e.swPath||"/serviceworker.js",g=e.disableCookies||!1,_=e.useLatest||!1,l=e.sdkVersion||"2.52.1";try{t&&(t=JSON.stringify(t))}catch(e){console.log("Failed to parse cards config",e)}if("undefined"!=typeof window&&document&&!window.Moengage){var u=n.toLowerCase(),w=document.createElement("script"),c=l&&!_?`https://cdn.moengage.com/release/${u}/versions/${l}/moe_webSdk.min.latest.js`:`https://cdn.moengage.com/release/${u}/moe_webSdk.min.latest.js`;w.type="text/javascript",w.text=`!function(e,n,i,t,a,r,o,d){if(!"${u}"||"{DC}"==="${u}")return console.error("Data center has not been passed correctly. Please follow the SDK installation instruction carefully.");var s=e[a]=e[a]||[];if(s.invoked=0,s&&s.initialised>0||s.invoked>0)return console.error("MoEngage Web SDK initialised multiple times. Please integrate the Web SDK only once!"),!1;e.moengage_object=a;var l={},g=function n(i){return function(){for(var n=arguments.length,t=Array(n),a=0;a<n;a++)t[a]=arguments[a];(e.moengage_q=e.moengage_q||[]).push({f:i,a:t})}},u=["track_event","add_user_attribute","add_first_name","add_last_name","add_email","add_mobile","add_user_name","add_gender","add_birthday","destroy_session","add_unique_user_id","update_unique_user_id","moe_events","call_web_push","track","location_type_attribute","track_page_view","getSdkVersion","setDebugLevel", "handle_page_change"],m={onsite:["getData","registerCallback"]};for(var c in u)l[u[c]]=g(u[c]);for(var v in m)for(var f in m[v])null==l[v]&&(l[v]={}),l[v][m[v][f]]=g(v+"."+m[v][f]);r=n.createElement(i),o=n.getElementsByTagName("head")[0],r.async=1,r.src=t,o.appendChild(r),e.moe=e.moe||function(){return(s.invoked=s.invoked+1,s.invoked>1)?(console.error("MoEngage Web SDK initialised multiple times. Please integrate the Web SDK only once!"),!1):(d=arguments.length<=0?void 0:arguments[0],l)},r.addEventListener("load",function(){if(d)return e[a]=e.moe(d),(e[a]&&(e[a].initialised=e[a].initialised+1||1)),!0}),r.addEventListener("error",function(){return console.error("Moengage Web SDK loading failed."),!1})}(window,document,"script","${c}","Moengage");\n Moengage = moe({\n app_id: "${a}",\n debug_logs: ${o},\n swPath: "${r}",\n cluster: "${n.toUpperCase()}",\n disableOnsite: ${d},\n disableCookies: ${g},\n disable_web_push: ${s},\n enableSPA: ${i},\n cards: ${t}\n });\n `,document.head.appendChild(w)}},isMoeLoaded:()=>{try{if("undefined"!=typeof window&&document&&window.Moengage)return!0}catch(e){return!1}return!1},track_event:(e,a)=>Moe.isMoeLoaded()&&window.Moengage.track_event(e,a),getSdkVersion:()=>Moe.isMoeLoaded()&&window.Moengage.getSdkVersion(),setDebugLevel:e=>Moe.isMoeLoaded()&&window.Moengage.setDebugLevel(e),add_unique_user_id:e=>Moe.isMoeLoaded()&&window.Moengage.add_unique_user_id(e),update_unique_user_id:e=>Moe.isMoeLoaded()&&window.Moengage.update_unique_user_id(e),add_user_attribute:(e,a)=>Moe.isMoeLoaded()&&window.Moengage.add_user_attribute(e,a),add_first_name:e=>Moe.isMoeLoaded()&&window.Moengage.add_first_name(e),add_last_name:e=>Moe.isMoeLoaded()&&window.Moengage.add_last_name(e),add_email:e=>Moe.isMoeLoaded()&&window.Moengage.add_email(e),add_mobile:e=>Moe.isMoeLoaded()&&window.Moengage.add_mobile(e),add_user_name:e=>Moe.isMoeLoaded()&&window.Moengage.add_user_name(e),add_gender:e=>Moe.isMoeLoaded()&&window.Moengage.add_gender(e),add_birthday:e=>Moe.isMoeLoaded()&&window.Moengage.add_birthday(e),destroy_session:()=>Moe.isMoeLoaded()&&window.Moengage.destroy_session(),call_web_push:e=>Moe.isMoeLoaded()&&window.Moengage.call_web_push(e),track_page_view:()=>Moe.isMoeLoaded()&&window.Moengage.track_page_view(),handle_page_change:()=>Moe.isMoeLoaded()&&window.Moengage.handle_page_change(),on_cards_loaded:()=>new Promise(((e,a)=>{"undefined"!=typeof window?window.Moengage.cards?(Moe.cards=window.Moengage.cards,e()):window.addEventListener("MOE_LIFECYCLE",(a=>{"CARDS_INITIALIZED"===a.detail.name&&(Moe.cards=window.Moengage.cards,e())})):a()})),cards:"undefined"!=typeof window&&window.Moengage&&window.Moengage.cards||{}};module.exports=Moe;
1
+ const Moe={initialize:e=>{var a=e.app_id,o=e.debug_logs||0,n=e.cluster||"DC_1",d=e.disable_onsite||!1,i=e.enableSPA||!1,t=e.cards||null,s=e.disable_web_push||!1,r=e.swPath||"/serviceworker.js",g=e.disableCookies||!1,_=e.useLatest||!1,l=e.sdkVersion||"2.52.2";try{t&&(t=JSON.stringify(t))}catch(e){console.log("Failed to parse cards config",e)}if("undefined"!=typeof window&&document&&!window.Moengage){var u=n.toLowerCase(),w=document.createElement("script"),M=l&&!_?`https://cdn.moengage.com/release/${u}/versions/${l}/moe_webSdk.min.latest.js`:`https://cdn.moengage.com/release/${u}/moe_webSdk.min.latest.js`;w.type="text/javascript",w.text=`!function(e,n,i,t,a,r,o,d){if(!"${u}"||"{DC}"==="${u}")return console.error("Data center has not been passed correctly. Please follow the SDK installation instruction carefully.");var s=e[a]=e[a]||[];if(s.invoked=0,s&&s.initialised>0||s.invoked>0)return console.error("MoEngage Web SDK initialised multiple times. Please integrate the Web SDK only once!"),!1;e.moengage_object=a;var l={},g=function n(i){return function(){for(var n=arguments.length,t=Array(n),a=0;a<n;a++)t[a]=arguments[a];(e.moengage_q=e.moengage_q||[]).push({f:i,a:t})}},u=["track_event","add_user_attribute","add_first_name","add_last_name","add_email","add_mobile","add_user_name","add_gender","add_birthday","destroy_session","add_unique_user_id","update_unique_user_id","moe_events","call_web_push","track","location_type_attribute","track_page_view","getSdkVersion","setDebugLevel","handle_page_change","identifyUser","getUserIdentities"],m={onsite:["getData","registerCallback"]};for(var c in u)l[u[c]]=g(u[c]);for(var v in m)for(var f in m[v])null==l[v]&&(l[v]={}),l[v][m[v][f]]=g(v+"."+m[v][f]);r=n.createElement(i),o=n.getElementsByTagName("head")[0],r.async=1,r.src=t,o.appendChild(r),e.moe=e.moe||function(){return(s.invoked=s.invoked+1,s.invoked>1)?(console.error("MoEngage Web SDK initialised multiple times. Please integrate the Web SDK only once!"),!1):(d=arguments.length<=0?void 0:arguments[0],l)},r.addEventListener("load",function(){if(d)return e[a]=e.moe(d),(e[a]&&(e[a].initialised=e[a].initialised+1||1)),!0}),r.addEventListener("error",function(){return console.error("Moengage Web SDK loading failed."),!1})}(window,document,"script","${M}","Moengage");\n Moengage = moe({\n app_id: "${a}",\n debug_logs: ${o},\n swPath: "${r}",\n cluster: "${n.toUpperCase()}",\n disableOnsite: ${d},\n disableCookies: ${g},\n disable_web_push: ${s},\n enableSPA: ${i},\n cards: ${t}\n });\n `,document.head.appendChild(w)}},isMoeLoaded:()=>{try{if("undefined"!=typeof window&&document&&window.Moengage)return!0}catch(e){return!1}return!1},track_event:(e,a)=>Moe.isMoeLoaded()&&window.Moengage.track_event(e,a),getSdkVersion:()=>Moe.isMoeLoaded()&&window.Moengage.getSdkVersion(),setDebugLevel:e=>Moe.isMoeLoaded()&&window.Moengage.setDebugLevel(e),add_unique_user_id:e=>Moe.isMoeLoaded()&&window.Moengage.add_unique_user_id(e),update_unique_user_id:e=>Moe.isMoeLoaded()&&window.Moengage.update_unique_user_id(e),identifyUser:e=>Moe.isMoeLoaded()&&window.Moengage.identifyUser(e),getUserIdentities:()=>Moe.isMoeLoaded()&&window.Moengage.getUserIdentities(),add_user_attribute:(e,a)=>Moe.isMoeLoaded()&&window.Moengage.add_user_attribute(e,a),add_first_name:e=>Moe.isMoeLoaded()&&window.Moengage.add_first_name(e),add_last_name:e=>Moe.isMoeLoaded()&&window.Moengage.add_last_name(e),add_email:e=>Moe.isMoeLoaded()&&window.Moengage.add_email(e),add_mobile:e=>Moe.isMoeLoaded()&&window.Moengage.add_mobile(e),add_user_name:e=>Moe.isMoeLoaded()&&window.Moengage.add_user_name(e),add_gender:e=>Moe.isMoeLoaded()&&window.Moengage.add_gender(e),add_birthday:e=>Moe.isMoeLoaded()&&window.Moengage.add_birthday(e),destroy_session:()=>Moe.isMoeLoaded()&&window.Moengage.destroy_session(),call_web_push:e=>Moe.isMoeLoaded()&&window.Moengage.call_web_push(e),track_page_view:()=>Moe.isMoeLoaded()&&window.Moengage.track_page_view(),handle_page_change:()=>Moe.isMoeLoaded()&&window.Moengage.handle_page_change(),on_cards_loaded:()=>new Promise(((e,a)=>{"undefined"!=typeof window?window.Moengage.cards?(Moe.cards=window.Moengage.cards,e()):window.addEventListener("MOE_LIFECYCLE",(a=>{"CARDS_INITIALIZED"===a.detail.name&&(Moe.cards=window.Moengage.cards,e())})):a()})),cards:"undefined"!=typeof window&&window.Moengage&&window.Moengage.cards||{}};module.exports=Moe;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moengage/web-sdk",
3
- "version": "2.52.1",
3
+ "version": "2.52.2",
4
4
  "description": "Moengage Web SDK package",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [