@moengage/web-sdk 2.60.1 → 2.61.0

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/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ declare interface InitData {
5
5
  app_id: string;
6
6
  cluster: string;
7
7
  debug_logs?: number;
8
+ project_id?: string;
8
9
  disable_onsite?: boolean;
9
10
  enableSPA?: boolean;
10
11
  cards?: {
@@ -79,11 +80,13 @@ declare interface InitData {
79
80
  };
80
81
  disable_web_push?: boolean;
81
82
  swPath?: string;
83
+ swScope?: string;
82
84
  disableCookies?: boolean;
83
85
  useLatest?: boolean;
84
86
  sdkVersion?: string;
85
87
  disableSdk?: boolean;
86
88
  proxyDomains?: ProxyDomains;
89
+ bots_list?: string[];
87
90
  }
88
91
 
89
92
  /**
@@ -209,22 +212,41 @@ declare function getUserId(): string;
209
212
  /**
210
213
  * Provides the value of the attribute passed as parameter
211
214
  * @param {string} attribute
215
+ * @param {string} userAttributeLevel - The level at which the user attribute is to be fetched. This is valid only for portfolio of DBs. If not provided, the attribute will be fetched at the 'PROJECT' level by default. Refer to `Attribute.USER_ATTRIBUTE_LEVEL` for possible values.
212
216
  * @return {*} returns the value of the attribute passed as parameter
213
217
  * if the attribute is not present, it returns empty string
214
218
  */
215
- declare function getUserAttribute(attribute: string): any;
219
+ declare function getUserAttribute(
220
+ attribute: string,
221
+ userAttributeLevel?: string,
222
+ ): any;
216
223
 
217
224
  /**
218
225
  * Adds a user attribute with the given name and value.
219
226
  * @param attrName - The name of the user attribute.
220
227
  * @param attrValue - The value of the user attribute.
228
+ * @param userAttributeLevel - The level at which the user attribute is to be set. This is valid only for portfolio of DBs. If not provided, the attribute will be set at the 'PROJECT' level by default. Refer to `Attribute.USER_ATTRIBUTE_LEVEL` for possible values.
221
229
  * @returns A Promise that resolves when the user attribute is added.
222
230
  */
223
231
  declare function add_user_attribute(
224
232
  attrName: string,
225
233
  attrValue: any,
234
+ userAttributeLevel?: string,
226
235
  ): Promise<any>;
227
236
 
237
+ /**
238
+ * Namespace for user attribute.
239
+ */
240
+ declare namespace Attribute {
241
+ /**
242
+ * Enumeration for user attribute levels.
243
+ */
244
+ enum USER_ATTRIBUTE_LEVEL {
245
+ PROJECT = 'PROJECT',
246
+ PORTFOLIO = 'PORTFOLIO',
247
+ }
248
+ }
249
+
228
250
  /**
229
251
  * Sets the first name of the user.
230
252
  * @param firstName - the first name of the user.
@@ -389,4 +411,5 @@ export {
389
411
  cards,
390
412
  onsite,
391
413
  InitData,
414
+ Attribute,
392
415
  };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- const Moe={initialize:e=>{var d=e.app_id,o=e.debug_logs||0,a=e.cluster||"DC_1",n=e.disable_onsite||!1,i=e.enableSPA||!1,s=e.cards||null,t=e.disable_web_push||!1,r=e.swPath||"/serviceworker.js",g=e.disableCookies||!1,l=e.useLatest||!1,M=e.sdkVersion||"2.60.01",w=e.disableSdk||!1,_=e.proxyDomains||null;try{s&&(s=JSON.stringify(s))}catch(e){console.log("Failed to parse cards config",e)}if("undefined"!=typeof window&&document&&!window.Moengage){var u=a.toLowerCase(),c=document.createElement("script"),m=M&&!l?`https://cdn.moengage.com/release/${u}/versions/${M}/moe_webSdk.min.latest.js`:`https://cdn.moengage.com/release/${u}/moe_webSdk.min.latest.js`;c.type="text/javascript",c.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","getSelfHandledOSM"]};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: "${d}",\n debug_logs: ${o},\n swPath: "${r}",\n cluster: "${a.toUpperCase()}",\n disableOnsite: ${n},\n disableCookies: ${g},\n disable_web_push: ${t},\n enableSPA: ${i},\n cards: ${s},\n disableSdk: ${w},\n proxyDomains: ${_}\n });\n `,document.head.appendChild(c)}},isMoeLoaded:()=>{try{if("undefined"!=typeof window&&document&&window.Moengage)return!0}catch(e){return!1}return!1},track_event:(e,d)=>Moe.isMoeLoaded()&&window.Moengage.track_event(e,d),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(),enableSdk:()=>Moe.isMoeLoaded()&&window.Moengage.enableSdk(),disableSdk:()=>Moe.isMoeLoaded()&&window.Moengage.disableSdk(),isSdkEnabled:()=>Moe.isMoeLoaded()&&window.Moengage.isSdkEnabled(),getUserId:()=>Moe.isMoeLoaded()&&window.Moengage.getUserId(),getUserAttribute:e=>Moe.isMoeLoaded()&&window.Moengage.getUserAttribute(e),add_user_attribute:(e,d)=>Moe.isMoeLoaded()&&window.Moengage.add_user_attribute(e,d),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,d)=>{"undefined"!=typeof window?window.Moengage.cards?(Moe.cards=window.Moengage.cards,e()):window.addEventListener("MOE_LIFECYCLE",d=>{"CARDS_INITIALIZED"===d.detail.name&&(Moe.cards=window.Moengage.cards,e())}):d()}),cards:"undefined"!=typeof window&&window.Moengage&&window.Moengage.cards||{},onsite:{getData:()=>Moe.isMoeLoaded()&&window.Moengage.onsite.getData(),registerCallback:e=>Moe.isMoeLoaded()&&window.Moengage.onsite.registerCallback(e),getSelfHandledOSM:e=>Moe.isMoeLoaded()&&window.Moengage.onsite.getSelfHandledOSM(e),selfHandledShown:e=>Moe.isMoeLoaded()&&window.Moengage.onsite.selfHandledShown(e),selfHandledClicked:e=>Moe.isMoeLoaded()&&window.Moengage.onsite.selfHandledClicked(e),selfHandledDismissed:e=>Moe.isMoeLoaded()&&window.Moengage.onsite.selfHandledDismissed(e)}};module.exports=Moe;
1
+ const Moe={initialize:e=>{var o=e.app_id,d=e.debug_logs||0,n=e.cluster||"DC_1",a=e.project_id||null,i=e.disable_onsite||!1,s=e.enableSPA||!1,t=e.cards||null,r=e.disable_web_push||!1,g=e.swPath||"/serviceworker.js",l=e.swScope||null,M=e.disableCookies||!1,w=e.useLatest||!1,_=e.sdkVersion||"2.61.00",u=e.disableSdk||!1,c=e.proxyDomains||null,m=e.bots_list||[];try{t&&(t=JSON.stringify(t))}catch(e){console.log("Failed to parse cards config",e)}try{m=JSON.stringify(m)}catch(e){console.log("Failed to parse bots list config",e)}try{c&&(c=JSON.stringify(c))}catch(e){console.log("Failed to parse proxy domains config",e)}if("undefined"!=typeof window&&document&&!window.Moengage){var b=n.toLowerCase(),f=document.createElement("script"),p=_&&!w?`https://cdn.moengage.com/release/${b}/versions/${_}/moe_webSdk.min.latest.js`:`https://cdn.moengage.com/release/${b}/moe_webSdk.min.latest.js`;f.type="text/javascript",f.text=`!function(e,n,i,t,a,r,o,d){if(!"${b}"||"{DC}"==="${b}")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","getSelfHandledOSM"]};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","${p}","Moengage");\n Moengage = moe({\n app_id: "${o}",\n debug_logs: ${d},\n swPath: "${g}",\n swScope: "${l}",\n cluster: "${n.toUpperCase()}",\n ${a?`project_id: "${a}",`:""}\n disableOnsite: ${i},\n disableCookies: ${M},\n disable_web_push: ${r},\n enableSPA: ${s},\n cards: ${t},\n disableSdk: ${u},\n proxyDomains: ${c},\n bots_list: ${m}\n });\n `,document.head.appendChild(f)}},isMoeLoaded:()=>{try{if("undefined"!=typeof window&&document&&window.Moengage)return!0}catch(e){return!1}return!1},track_event:(e,o)=>Moe.isMoeLoaded()&&window.Moengage.track_event(e,o),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(),enableSdk:()=>Moe.isMoeLoaded()&&window.Moengage.enableSdk(),disableSdk:()=>Moe.isMoeLoaded()&&window.Moengage.disableSdk(),isSdkEnabled:()=>Moe.isMoeLoaded()&&window.Moengage.isSdkEnabled(),getUserId:()=>Moe.isMoeLoaded()&&window.Moengage.getUserId(),getUserAttribute:(e,o)=>Moe.isMoeLoaded()?o&&"string"==typeof o?window.Moengage.getUserAttribute(e,o):window.Moengage.getUserAttribute(e):null,add_user_attribute:(e,o,d)=>!!Moe.isMoeLoaded()&&(d&&"string"==typeof d?window.Moengage.add_user_attribute(e,o,d):window.Moengage.add_user_attribute(e,o)),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,o)=>{"undefined"!=typeof window?window.Moengage.cards?(Moe.cards=window.Moengage.cards,e()):window.addEventListener("MOE_LIFECYCLE",o=>{"CARDS_INITIALIZED"===o.detail.name&&(Moe.cards=window.Moengage.cards,e())}):o()}),cards:"undefined"!=typeof window&&window.Moengage&&window.Moengage.cards||{},onsite:{getData:()=>Moe.isMoeLoaded()&&window.Moengage.onsite.getData(),registerCallback:e=>Moe.isMoeLoaded()&&window.Moengage.onsite.registerCallback(e),getSelfHandledOSM:e=>Moe.isMoeLoaded()&&window.Moengage.onsite.getSelfHandledOSM(e),selfHandledShown:e=>Moe.isMoeLoaded()&&window.Moengage.onsite.selfHandledShown(e),selfHandledClicked:e=>Moe.isMoeLoaded()&&window.Moengage.onsite.selfHandledClicked(e),selfHandledDismissed:e=>Moe.isMoeLoaded()&&window.Moengage.onsite.selfHandledDismissed(e)},Attribute:{USER_ATTRIBUTE_LEVEL:{PROJECT:"PROJECT",PORTFOLIO:"PORTFOLIO"}}};module.exports=Moe;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moengage/web-sdk",
3
- "version": "2.60.01",
3
+ "version": "2.61.00",
4
4
  "description": "Moengage Web SDK package",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [