@moengage/web-sdk 1.0.14 → 2.46.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.
@@ -0,0 +1,185 @@
1
+ /**
2
+ * The configuration used while initializing the SDK.
3
+ */
4
+ declare interface InitData {
5
+ app_id: string;
6
+ cluster: string;
7
+ debugLogs?: number;
8
+ disableOnsite?: boolean;
9
+ enableSPA?: boolean;
10
+ cards?: any;
11
+ disableWebPush?: boolean;
12
+ swPath?: string;
13
+ disableCookies?: boolean;
14
+ useLatest?: boolean;
15
+ }
16
+
17
+ /**
18
+ * Initializes the SDK.
19
+ * @param initData - configuration for SDK intialization.
20
+ */
21
+ declare function initialize(initData: InitData): void;
22
+
23
+ /**
24
+ * Indicates if the SDK has been loaded in the DOM and is available for use.
25
+ * @returns `true` if the SDK has been successfully loaded; `false` otherwise.
26
+ */
27
+ declare function isMoeLoaded(): boolean;
28
+
29
+ /**
30
+ * Tracks an event with the given name and attributes.
31
+ * @param eventName - The name of the event to track.
32
+ * @param eventAttrs - The attributes associated with the event.
33
+ * @returns A Promise that resolves when the event tracking is completed.
34
+ */
35
+ declare function track_event(eventName: string, eventAttrs: any): Promise<any>;
36
+
37
+ /**
38
+ * Provides the current-build version.
39
+ * @returns The current version of the SDK in use.
40
+ */
41
+ declare function getSdkVersion(): string;
42
+
43
+ /**
44
+ * Explicitly set new debug level. To be used to see log messages in live environment too.
45
+ * @note This does not append '_DEBUG' to the workspace ID.
46
+ * @param level Debug level to set.
47
+ */
48
+ declare function setDebugLevel(level: number): Promise<void>;
49
+
50
+ /**
51
+ * Sets an identifier for the user.
52
+ * @param id - The identifier associated to the user.
53
+ * @returns A Promise that resolves when setting of the identifier is complete.
54
+ */
55
+ declare function add_unique_user_id(id: string | number): Promise<any>;
56
+
57
+ /**
58
+ * Updates the identifier of the user whose identifier is already set.
59
+ * @param id - The identifier associated to the user.
60
+ * @returns A Promise that resolves when the identifier is updated.
61
+ */
62
+ declare function update_unique_user_id(id: string | number): Promise<any>;
63
+
64
+ /**
65
+ * Adds a user attribute with the given name and value.
66
+ * @param attrName - The name of the user attribute.
67
+ * @param attrValue - The value of the user attribute.
68
+ * @returns A Promise that resolves when the user attribute is added.
69
+ */
70
+ declare function add_user_attribute(
71
+ attrName: string,
72
+ attrValue: any,
73
+ ): Promise<any>;
74
+
75
+ /**
76
+ * Sets the first name of the user.
77
+ * @param firstName - the first name of the user.
78
+ * @returns A Promise that resolves when the first name is set.
79
+ */
80
+ declare function add_first_name(firstName: string): Promise<any>;
81
+
82
+ /**
83
+ * Sets the last name of the user.
84
+ * @param lastName - the last name of the user.
85
+ * @returns A Promise that resolves when the last name is set.
86
+ */
87
+ declare function add_last_name(lastName: string): Promise<any>;
88
+
89
+ /**
90
+ * Sets the email of the user.
91
+ * @param email - the email of the user.
92
+ * @returns A Promise that resolves when the email is set.
93
+ */
94
+ declare function add_email(email: string): Promise<any>;
95
+
96
+ /**
97
+ * Sets the mobile number of the user.
98
+ * @param mobile - the mobile number of the user.
99
+ * @returns A Promise that resolves when the mobile number is set.
100
+ */
101
+ declare function add_mobile(mobile: string): Promise<any>;
102
+
103
+ /**
104
+ * Sets the name of the user.
105
+ * @param user_name - the name of the user.
106
+ * @returns A Promise that resolves when the name is set.
107
+ */
108
+ declare function add_user_name(user_name: string): Promise<any>;
109
+
110
+ /**
111
+ * Sets the gender of the user.
112
+ * @param gender - the gender of the user.
113
+ * @returns A Promise that resolves when the gender is set.
114
+ */
115
+ declare function add_gender(gender: string): Promise<any>;
116
+
117
+ /**
118
+ * Sets the birthday of the user.
119
+ * @param dob - the birthday of the user.
120
+ * @returns A Promise that resolves when the birthday is set.
121
+ */
122
+ declare function add_birthday(dob: Date): Promise<any>;
123
+
124
+ /**
125
+ * Logs out the current user.
126
+ * @returns A Promise that resolves when the user is logged out.
127
+ */
128
+ declare function destroy_session(): Promise<any>;
129
+
130
+ /**
131
+ * Starts the web push operations.
132
+ * @note Self-handled web push must be configured from MoEngage dashboard in order to use this method.
133
+ */
134
+ declare function call_web_push(config?: any): void;
135
+
136
+ /**
137
+ * Tracks events related to page-view.
138
+ * @returns A Promise that resolves when tracking of page-view events is completed.
139
+ */
140
+ declare function track_page_view(): Promise<any>;
141
+
142
+ /**
143
+ * Enforces the functionaly of page-change.
144
+ * Tracks page-view events and resets all the SDK modules.
145
+ */
146
+ declare function handle_page_change(): void;
147
+
148
+ /**
149
+ * Emits an event on the window object when the cards module has been successfully initialized.
150
+ * Use this method at the beginning of your code. Start using the cards module after the Promise resolves.
151
+ * @note Refer this guide on how to use the cards module: https://developers.moengage.com/hc/en-us/articles/9526886582292-Cards
152
+ * @returns A Promise that resolves when the cards module is successfully initialized.
153
+ */
154
+ declare function on_cards_loaded(): Promise<any>;
155
+
156
+ /**
157
+ * Contains the properties and methods of the cards module.
158
+ * @note Refer this guide on how to use the cards module: https://developers.moengage.com/hc/en-us/articles/9526886582292-Cards
159
+ */
160
+ declare const cards: any;
161
+
162
+ export {
163
+ initialize,
164
+ isMoeLoaded,
165
+ track_event,
166
+ getSdkVersion,
167
+ setDebugLevel,
168
+ add_unique_user_id,
169
+ update_unique_user_id,
170
+ add_user_attribute,
171
+ add_first_name,
172
+ add_last_name,
173
+ add_email,
174
+ add_mobile,
175
+ add_user_name,
176
+ add_gender,
177
+ add_birthday,
178
+ destroy_session,
179
+ call_web_push,
180
+ track_page_view,
181
+ handle_page_change,
182
+ on_cards_loaded,
183
+ cards,
184
+ InitData,
185
+ };
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.version||!1;try{t&&(t=JSON.stringify(t))}catch(e){console.log("Failed to parse cards config",e)}if(window&&document&&!window.Moengage){var l=n.toLowerCase(),u=document.createElement("script"),c=_?`https://cdn.moengage.com/release/${l}/versions/${_}/moe_webSdk.min.latest.js`:`https://cdn.moengage.com/release/${l}/moe_webSdk.min.latest.js`;u.type="text/javascript",u.text=`!function(e,n,i,t,a,r,o,d){if(!"${l}"||"{DC}"==="${l}")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.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].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(u)}},isMoeLoaded:()=>{try{if(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(),push_to_q:()=>{(window.moengage_q=window.moengage_q||[]).push({f:"track_event",a:[CONSTANTS.EVENTS.IMPRESSION,{campaign_id:campaign.id,...campaign.context}]})}};export default 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;try{t&&(t=JSON.stringify(t))}catch(e){console.log("Failed to parse cards config",e)}if(window&&document&&!window.Moengage){var l=n.toLowerCase(),u=document.createElement("script"),c=_?`https://cdn.moengage.com/release/${l}/moe_webSdk.min.latest.js`:`https://cdn.moengage.com/release/${l}/versions/2.46.0/moe_webSdk.min.latest.js`;u.type="text/javascript",u.text=`!function(e,n,i,t,a,r,o,d){if(!"${l}"||"{DC}"==="${l}")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.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].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(u)}},isMoeLoaded:()=>{try{if(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)=>{window.addEventListener("MOE_LIFECYCLE",(a=>{"CARDS_INITIALIZED"===a.detail.name&&(Moe.cards=window.Moengage.cards,e())}))})),cards:{}};export default Moe;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moengage/web-sdk",
3
- "version": "1.0.14",
3
+ "version": "2.46.0",
4
4
  "description": "Moengage Web SDK package",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [
@@ -20,4 +20,4 @@
20
20
  "type": "git",
21
21
  "url": "git+https://github.com/moengage/webSDK.git"
22
22
  }
23
- }
23
+ }