1(function (document, window) { 2 3 var MoEngageVedantu = function () { 4 var MOENGAGE_APP_ID = !!window && !!window.config && !!window.config.moengage && window.config.moengage.appId; 5 var ANALYTICS_KEY = "MOE_STORAGE_DATA"; 6 var USER_ATTRIBUTE_STORAGE_KEY = "MOE_USER_ATTRIBUTE_STORAGE_DATA"; 7 var SYNCH_TIME = 300; 8 var UA_SYNCH_TIME = 300; 9 var localAnalyticsData = null; 10 var localUAData = []; 11 var timerObj = null; 12 var uaTimerObj = null; 13 var timeoutObj = null; 14 var isDataSynchInProgress = false; 15 var userAttributesSyncInProgress = false; 16 var dataSynchedOnPageLoad = false; 17 var uaSynchedOnPageLoad = false; 18 var userDataFromDataLayer = null; 19 var isMoELoaded = false; 20 var sessionData = !!window.vedantuSessionData ? window.vedantuSessionData : null; 21 var isProductionDebugLog = (!!window.config && window.config.mode == "PROD") ? 0 : 1; 22 var isAVSKPage = false; 23 var uaSubStringEndIndex = 60; 24 var isUnderDelay = false; //for delaying events to send to moe from user logins in till moe identifies its exiting user in their DB. random time of 2min 25 26 var VSKUrls = [ 27 '/superkids', '/superkids/', 28 '/supercoders', '/supercoders/', 29 '/superreaders', '/superreaders/', 30 '/superspeakers', '/superspeakers/', 31 '/earlylearning', '/earlylearning/', 32 '/superkids/course', '/superkids/course/', 33 '/supercoders/course', '/supercoders/course/', 34 '/superkids/faqs', '/superkids/faqs/', 35 '/supercoders/faqs', '/supercoders/faqs/', 36 '/superkids/lil-champs', '/superkids/lil-champs/', 37 '/supercoders/lil-champs', '/supercoders/lil-champs/', 38 '/superkids/yong-learners', '/superkids/yong-learners/', 39 '/supercoders/yong-learners', '/supercoders/yong-learners/', 40 '/superkids-early-achive', '/superkids-early-achive/', 41 '/superkids/superteacher', '/superkids/superteacher/', 42 '/supercoders/superteacher', '/supercoders/superteacher/', 43 '/superkids/pro-coders', '/superkids/pro-coders/', 44 '/supercoders/pro-coders', '/supercoders/pro-coders/', 45 '/superkids/freetrial', '/superkids/freetrial/', 46 '/supercoders/freetrial', '/supercoders/freetrial/', 47 '/superspeakers/freetrial', '/superspeakers/freetrial/', 48 '/superreaders/gliding-readers', '/superreaders/gliding-readers/', 49 '/superreaders/soaring-readers', '/superreaders/soaring-readers/', 50 '/superreaders/democertificate', '/superreaders/democertificate/', 51 '/superkids/courses', '/superkids/courses/', 52 '/supercoders/courses', '/supercoders/courses/', 53 '/superkids/courses/1-2', '/superkids/courses/1-2/', 54 '/supercoders/courses/1-2', '/supercoders/courses/1-2/', 55 '/superkids/courses/3-4', '/superkids/courses/3-4/', 56 '/supercoders/courses/3-4', '/supercoders/courses/3-4/', 57 '/superkids/courses/5-6', '/superkids/courses/5-6/', 58 '/supercoders/courses/5-6', '/supercoders/courses/5-6/', 59 '/superkids/courses/7-8', '/superkids/courses/7-8/', 60 '/supercoders/courses/7-8', '/supercoders/courses/7-8/', 61 '/superreaders/freetrial', '/superreaders/freetrial/', 62 '/superreaders/stories/king-ring', '/superreaders/stories/king-ring/', 63 '/superreaders/stories/the-intelligent-cook', '/superreaders/stories/the-intelligent-cook/', 64 '/superreaders/stories/yogi-learns-yoga', '/superreaders/stories/yogi-learns-yoga/', 65 '/superreaders/stories/the-buzzing-bees', '/superreaders/stories/the-buzzing-bees/', 66 '/superreaders/stories/iggy-the-iguana', '/superreaders/stories/iggy-the-iguana/' 67 ]; 68 69 if (VSKUrls.indexOf(window.location.pathname) >= 0) { 70 isAVSKPage = true; 71 MOENGAGE_APP_ID = !!window && !!window.config && !!window.config.moengage && window.config.moengage.vskAppId; 72 } 73 74 if (!!window.vedantuSessionData) { 75 delete window.vedantuSessionData; 76 } 77 78 var getCookieValue = function (name) { 79 /**
80 * @description- To get the cookie value. 81 * @returns {string | null}- returns the cookie value if present or returns null. 82 */ 83 var value = "; " + document.cookie; 84 var parts = value.split("; " + name + "="); 85 if (parts.length == 2) return parts.pop().split(";").shift(); 86 return null; 87 }; 88 89 function deleteCookie(name) { 90 if (window) { 91 document.cookie = name + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;'; 92 } 93 } 94 95 var addUserAttribute = function (attributeName, attributeValue, attributeType) { 96 /** 97 * @description- This function adds a user attribute to Moengage. Exposed outside function. Can be used by MoEngageVedantu.addUserAttribute. 98 * @param {string} attributeName- This is the attribute name. This param is required. If not valid or absent, user attribute will not be added. 99 * @param {string} attributeValue- This is the attribute value. This param is required. 100 * @returns {undefined} 101 */ 102 try { 103 if (!!MOENGAGE_APP_ID && !!Moengage && attributeValue != null && attributeValue != undefined) { 104 localUAData.push({ type: !!attributeType ? attributeType : "aua", name: attributeName, value: attributeValue }); 105 syncUserAttributesInit(); 106 } 107 } catch (err) { 108 console.log("moengage something went wrong " + err); 109 } 110 }; 111 112 var addData = function (dataEvent, dataCustomObj) { 113 /** 114 * @description- This function adds data to localAnalyticsData and localStorage. This function also appends the UTM parameters to the event 115 * object(dataCustomObj) from URL and Cookies. 116 * @param {string} dataEvent- This is the event name. This param is required. If not valid or absent, event will not be sent to Moengage. 117 * @param {object} dataCustomObj- This is the event values/attributes. 118 * @returns {undefined} 119 */ 120 try { 121 if (!!MOENGAGE_APP_ID && !!dataEvent) { 122 123 dataCustomObj = !!dataCustomObj ? dataCustomObj : {}; 124 125 localAnalyticsData = !!localAnalyticsData && !!localAnalyticsData.length ? localAnalyticsData : []; 126 if (typeof dataCustomObj == "object" && Object.keys(dataCustomObj).length > 0) { 127 var pageUrlQueryParams = !!window && !!window.queryParamModule && window.queryParamModule.getAllUrlParams(); 128 var cookieUtms = getCookieValue("utmParams"); 129 if (!!cookieUtms) { 130 cookieUtms = window.JSON.parse(decodeURIComponent(cookieUtms)); 131 } 132 133 if (!!pageUrlQueryParams && !!pageUrlQueryParams.doubtApp) { 134 dataCustomObj.fromApp = true; 135 } else { 136 dataCustomObj.fromApp = false; 137 }; 138 139 dataCustomObj.utm_campaign = (!!pageUrlQueryParams && !!pageUrlQueryParams.utm_campaign && pageUrlQueryParams.utm_campaign) 140 || (!!cookieUtms && !!cookieUtms.utm_campaign && cookieUtms.utm_campaign) || null; 141 dataCustomObj.utm_source = (!!pageUrlQueryParams && !!pageUrlQueryParams.utm_source && pageUrlQueryParams.utm_source) 142 || (!!cookieUtms && !!cookieUtms.utm_source && cookieUtms.utm_source) || null; 143 dataCustomObj.utm_medium = (!!pageUrlQueryParams && !!pageUrlQueryParams.utm_medium && pageUrlQueryParams.utm_medium) 144 || (!!cookieUtms && !!cookieUtms.utm_medium && cookieUtms.utm_medium) || null;
145 dataCustomObj.utm_content = (!!pageUrlQueryParams && !!pageUrlQueryParams.utm_content && pageUrlQueryParams.utm_content) 146 || (!!cookieUtms && !!cookieUtms.utm_content && cookieUtms.utm_content) || null; 147 dataCustomObj.utm_term = (!!pageUrlQueryParams && !!pageUrlQueryParams.utm_term && pageUrlQueryParams.utm_term) 148 || (!!cookieUtms && !!cookieUtms.utm_term && cookieUtms.utm_term) || null; 149 } 150 var data = { moe_event_name: dataEvent, moe_event_customobj: dataCustomObj }; 151 var newStorageData = []; 152 if (dataSynchedOnPageLoad) { 153 localAnalyticsData.push(data); 154 newStorageData = localAnalyticsData; 155 } else { 156 newStorageData = getData() || []; 157 newStorageData.push(data); 158 } 159 window.localStorage.setItem(ANALYTICS_KEY, window.JSON.stringify(newStorageData)); 160 if (!!timerObj) { 161 clearInterval(timerObj); 162 }; 163 if (!!timeoutObj) { 164 clearTimeout(timeoutObj); 165 }; 166 timeoutObj = setTimeout(function () { 167 syncDataInit(); 168 }, 350); 169 } 170 } catch (err) { 171 console.log("something went wrong adding data moengage", err); 172 } 173 }; 174 175 var getData = function () { 176 /** 177 * @description- This function gets data from localStorage on page load. 178 * @returns {object}- returns localStorage data as on object. 179 */ 180 var analyticsData = null; 181 var analyticsData = window.localStorage.getItem(ANALYTICS_KEY); 182 if (!!analyticsData) { 183 analyticsData = window.JSON.parse(analyticsData); 184 } 185 return analyticsData; 186 }; 187 188 var getUAData = function () { 189 /** 190 * @description- This function gets data from localStorage on page load. 191 * @returns {object}- returns localStorage data as on object. 192 */ 193 var uaData = null; 194 var uaData = window.localStorage.getItem(USER_ATTRIBUTE_STORAGE_KEY); 195 if (!!uaData) { 196 uaData = window.JSON.parse(uaData); 197 } 198 return uaData; 199 }; 200 201 var synchDataToMoEngage = function () { 202 /** 203 * @description- This function is used to sync data to Moengage. 204 * @returns {undefined} 205 */ 206 try { 207 if (isDataSynchInProgress || isUnderDelay) { 208 return; 209 } 210 var synchData = null; 211 if (localAnalyticsData && localAnalyticsData.length > 0 && !isDataSynchInProgress && isMoELoaded) { 212 isDataSynchInProgress = true; 213 synchData = localAnalyticsData[0]; 214 var newCustomObj = {}; 215 Object.keys(synchData.moe_event_customobj).forEach(function (key) { 216 var keyValue = synchData.moe_event_customobj[key]; 217 if (keyValue !== null) { 218 if (typeof (keyValue) == 'object') { 219 newCustomObj[key] = keyValue || null; 220 } else { 221 newCustomObj[key] = String(synchData.moe_event_customobj[key]) || null; 222 } 223 }; 224 }); 225 try { 226 !!Moengage && Moengage.track_event(synchData.moe_event_name, newCustomObj).then(function (resp) { 227 localAnalyticsData.splice(0, 1); 228 window.localStorage.setItem(ANALYTICS_KEY, window.JSON.stringify(localAnalyticsData)); 229 isDataSynchInProgress = false;
230 }).catch(function (err) { 231 isDataSynchInProgress = false; 232 }); 233 } catch (err) { 234 isDataSynchInProgress = false; 235 console.log("moengage something went wrong " + err); 236 } 237 }; 238 } catch (err) { 239 console.log("moengage something went wrong " + err); 240 } 241 }; 242 243 function clearDataFromLS() { 244 localUAData.splice(0, 1); 245 window.localStorage.setItem(USER_ATTRIBUTE_STORAGE_KEY, window.JSON.stringify(localUAData)); 246 userAttributesSyncInProgress = false; 247 } 248 249 var syncUserAttributesToMoEngage = function () { 250 /** 251 * @description- This function is used to sync data to Moengage. 252 * @returns {undefined} 253 */ 254 try { 255 if (userAttributesSyncInProgress) { 256 return; 257 } 258 var uaData = null; 259 if (localUAData && localUAData.length > 0 && !userAttributesSyncInProgress && isMoELoaded) { 260 userAttributesSyncInProgress = true; 261 uaData = localUAData[0]; 262 try { 263 var uaPromise; 264 if (uaData.type == "aua") { 265 uaPromise = Moengage.add_user_attribute(uaData.name, uaData.value) 266 } else if (uaData.type == "uuui") { 267 uaPromise = Moengage.update_unique_user_id(uaData.value) 268 } else if (uaData.type == "auui") { 269 uaPromise = Moengage.add_unique_user_id(uaData.value) 270 } else if (uaData.type == "afn") { 271 uaPromise = Moengage.add_first_name(uaData.value) 272 } else if (uaData.type == "aln") { 273 uaPromise = Moengage.add_last_name(uaData.value) 274 } else if (uaData.type == "am") { 275 uaPromise = Moengage.add_mobile(uaData.value) 276 } else if (uaData.type == "ae") { 277 uaPromise = Moengage.add_email(uaData.value) 278 } 279 if (!!uaPromise) { 280 uaPromise.then(function (resp) { 281 clearDataFromLS(); 282 }).catch(function (err) { 283 userAttributesSyncInProgress = false; 284 }) 285 } else { 286 clearDataFromLS() 287 } 288 } catch (err) { 289 userAttributesSyncInProgress = false; 290 console.log("moengage something went wrong " + err); 291 } 292 } else if (localUAData && localUAData.length == 0) { 293 clearInterval(uaTimerObj); 294 }; 295 } catch (err) { 296 console.log("moengage something went wrong " + err); 297 } 298 }; 299 300 301 var MoEngageInitSetup = function () { 302 /** 303 * @description- Main MoEngage function for Moengage initialization and setting user attributes based on loggedIn or not. 304 * @returns {undefined} 305 */ 306 if (!!MOENGAGE_APP_ID) { 307 deleteCookie(ANALYTICS_KEY); 308 function setDataLayerData(e) { 309 userDataFromDataLayer = e; 310 }; 311 312 var isLoggedIn = !!sessionData; 313 314 function resetData() { 315 userDataFromDataLayer = null; 316 dataSynchedOnPageLoad = false; 317 isDataSynchInProgress = false; 318 localAnalyticsData = null; 319 window.localStorage.removeItem(ANALYTICS_KEY); 320 window.localStorage.removeItem(USER_ATTRIBUTE_STORAGE_KEY); 321 window.localStorage.removeItem("VSKLoginMoEDelay"); 322 } 323 324 function trimTheUAValue(value) { 325 try { 326 return (!!value && value.toString().substring(0, uaSubStringEndIndex)) || null; 327 } catch (error) { 328 return value; 329 } 330 } 331 332 if (!window.VED_STATIC_PAGE && !isLoggedIn) { 333 resetData(); 334 } 335 336 // When MoEngage is LIVE for first time, to register already logged in users to MoEnagage 337 window.removeEventListener('dataLayerLoaded', setDataLayerData, true); 338 window.addEventListener('dataLayerLoaded', setDataLayerData, true); 339 340 window.addEventListener('MOE_LIFECYCLE', function (event) { 341 if (event.detail.name == "SETTINGS_FETCHED") { 342 var moengageLocalStorageData = Moengage.vitals(); 343 var moengageStoredUserId = null; 344 var isMoEngageLoggedIn = false;
345 var attributes = moengageLocalStorageData.userDetails.attributes; 346 347 function destroyUserEntityMoEngage(cb) { 348 try { 349 Moengage.destroy_session().then(function (resp) { 350 resetData(); 351 if (typeof cb == "function" && !!cb) { 352 cb(); 353 } 354 }); 355 } catch (err) { 356 console.log("moengage something went wrong " + err); 357 } 358 } 359 360 function updateChangedUserAttributes(sessionDataUpdate) { 361 362 if (!!sessionDataUpdate.userId) { 363 364 var userAttributesSubList1 = ["grade", "board", "target", "examTargets", "parentContactNumber", "parentFirstName"]; 365 // var userAttributesSubList2 = ["isContactNumberVerified", "locationInfo", "role", "phoneCode", "isEmailVerified", "parentEmails"]; 366 367 //Just sending data if url changes from VSK to Non VSK and visa-versa 368 var prevPageUrl = document.referrer; 369 var currentPageUrl = window.location.pathname; 370 var sendUAtoMoe = !prevPageUrl ? true : false; 371 372 if (!!prevPageUrl) { 373 var prevPageUrlObj = new window.URL(prevPageUrl); 374 if (prevPageUrlObj.origin !== window.location.origin) { 375 sendUAtoMoe = true; 376 } 377 prevPageUrl = prevPageUrl.split("?")[0]; 378 prevPageUrl = prevPageUrl.replace(window.location.origin, ""); 379 } 380 381 if (!sendUAtoMoe && VSKUrls.indexOf(prevPageUrl) < 0 && VSKUrls.indexOf(currentPageUrl) > 0) { 382 sendUAtoMoe = true; 383 } else if (!sendUAtoMoe && VSKUrls.indexOf(prevPageUrl) > 0 && VSKUrls.indexOf(currentPageUrl) < 0) { 384 sendUAtoMoe = true; 385 } 386 387 addUserAttribute(null, sessionDataUpdate.userId, "auui"); 388 389 for (var index = 0; index < attributes.length; index++) { 390 if (userAttributesSubList1.indexOf(attributes[index].key) < 0) { 391 // if (((sessionDataUpdate && sessionDataUpdate[attributes[index].key]) || null) && (sessionDataUpdate && sessionDataUpdate[attributes[index].key] != attributes[index].value)) { 392 // Moengage.add_user_attribute(attributes[index].key, sessionDataUpdate[attributes[index].key] || null); 393 // } 394 // if (sendUAtoMoe && sessionDataUpdate && attributes[index].key in sessionDataUpdate) { 395 // addUserAttribute(attributes[index].key, attributes[index].key in sessionDataUpdate ? sessionDataUpdate[attributes[index].key] : null); 396 // } 397 } else { 398 var newValue = null; 399 newValue = attributes[index].key in sessionDataUpdate ? sessionDataUpdate[attributes[index].key] 400 : (sessionDataUpdate.studentInfo && attributes[index].key in sessionDataUpdate.studentInfo ? sessionDataUpdate.studentInfo[attributes[index].key] : null); 401 // if (newValue && newValue != attributes[index].value) { 402 // Moengage.add_user_attribute(attributes[index].key, newValue || null); 403 // } 404 newValue = trimTheUAValue(newValue); 405 if (sendUAtoMoe && newValue) { 406 addUserAttribute(attributes[index].key, newValue || null); 407 } 408 } 409 } 410 411 if (!!sendUAtoMoe) { 412 addUserAttribute(null, trimTheUAValue(sessionDataUpdate.firstName) || null, "afn"); 413 addUserAttribute(null, trimTheUAValue(sessionDataUpdate.lastName) || null, "aln"); 414 addUserAttribute(null, String(!!sessionDataUpdate.phoneCode ? sessionDataUpdate.phoneCode : "91") + sessionDataUpdate.contactNumber, "am"); 415 addUserAttribute(null, trimTheUAValue(sessionDataUpdate.email) || null, "ae"); 416 checkPaidUserOrNot(true); 417 } else { 418 checkPaidUserOrNot(); 419 } 420 } 421 }; 422 function disableAPIForWindow() { 423 var disableAPI = false;
424 var currentTime = new Date().getTime(); 425 disableAPI = (window.config.apiBlockWindow && window.config.apiBlockWindow.start <= currentTime && window.config.apiBlockWindow.end >= currentTime); 426 return disableAPI; 427 }; 428 429 function checkPaidUserOrNot(sendAnyWay) { 430 if (disableAPIForWindow() || sessionData === null || (sessionData && sessionData.role != 'STUDENT')) { 431 return; 432 } 433 var ajaxModule = (!!window && window.ajaxModule) || (!!window && !!window.exposedMdules && window.exposedMdules.ajaxModule); 434 var paidUserMoeValue; 435 attributes.forEach(attribute => { 436 if (attribute.key == "paidUser") { 437 paidUserMoeValue = attribute.value; 438 } 439 }); 440 if (!!ajaxModule && !!ajaxModule.formSubSystemPath && !!ajaxModule.ajax && (sendAnyWay || !paidUserMoeValue)) { 441 var url = ajaxModule.formSubSystemPath('dinero', '/account/checkAnyPreviousOrders'); 442 ajaxModule.ajax(url, 'GET', null, null, function (response) { 443 var resp = JSON.parse(response); 444 if ((paidUserMoeValue != (!resp.success) && paidUserMoeValue !== true) || sendAnyWay) { 445 addUserAttribute("paidUser", !resp.success); 446 } 447 }); 448 } 449 } 450 451 for (var index = 0; index < attributes.length; index++) { 452 if (attributes[index].key == "USER_ATTRIBUTE_UNIQUE_ID") { 453 isMoEngageLoggedIn = true; 454 moengageStoredUserId = attributes[index].value; 455 break; 456 } 457 } 458 459 if (!window.VED_STATIC_PAGE && !isLoggedIn && isMoEngageLoggedIn) { 460 // When user is not logged in but has MoEngage Data, logging out from MoEngagae 461 destroyUserEntityMoEngage(); 462 } else if (isLoggedIn && !isMoEngageLoggedIn) { 463 if (typeof sessionData !== 'undefined' && sessionData !== null) { 464 setUserEntityMoEngage(sessionData, true); 465 } else if (!!userDataFromDataLayer) { 466 setUserEntityMoEngage(userDataFromDataLayer); 467 } 468 } else if (isLoggedIn && isMoEngageLoggedIn) { 469 if (typeof sessionData !== 'undefined' && sessionData !== null && sessionData.userId != moengageStoredUserId) { 470 destroyUserEntityMoEngage(function () { 471 setUserEntityMoEngage(sessionData, true); 472 moengageStoredUserId = sessionData.userId; 473 }); 474 } else if (!!sessionData) { 475 updateChangedUserAttributes(sessionData); 476 } 477 } 478 479 // var VSKLoginMoEDelayCookieValue = window.localStorage.getItem("VSKLoginMoEDelay"); 480 // if (!!VSKLoginMoEDelayCookieValue) { 481 // isUnderDelay = true; 482 // var currentTime = new Date(); 483 // currentTime.setMilliseconds(0); 484 // var cookieTime = new Date(Number(VSKLoginMoEDelayCookieValue)); 485 // var diffTimeSec = cookieTime.getTime() - currentTime.getTime(); 486 // if (diffTimeSec > 2 * 60 * 1000) { 487 // isUnderDelay = false;
488 // window.localStorage.removeItem("VSKLoginMoEDelay"); 489 // } else { 490 // isUnderDelay = true; 491 // setTimeout(function () { 492 // isUnderDelay = false; 493 // window.localStorage.removeItem("VSKLoginMoEDelay"); 494 // }, diffTimeSec); 495 // } 496 // } 497 498 function handleUpdateData(data) { 499 if(data && data.detail){ 500 setUserEntityMoEngage(data); 501 } else { 502 resetData(); 503 } 504 } 505 506 function handleLogin(data) { 507 // if (!!isAVSKPage) { 508 // isUnderDelay = true; 509 // var currentTime = new Date(); 510 // currentTime.setMilliseconds(0); 511 // currentTime.setMinutes 512 // window.localStorage.setItem("VSKLoginMoEDelay", (currentTime.getTime()+2*60*1000)); 513 // setTimeout(function () { 514 // isUnderDelay = false; 515 // window.localStorage.removeItem("VSKLoginMoEDelay"); 516 // }, 2 * 60 * 1000); 517 // } 518 setUserEntityMoEngage(data); 519 } 520 521 function handleSignUpEvent(data) { 522 try { 523 var resp = !!data && (data.detail || data); 524 resp = !!resp && !!resp.user && resp.user; 525 resp = !!resp ? resp : data; 526 resp = !!resp ? resp : null; 527 if(resp.userId || resp.id){ 528 !!window.MoEngageVedantu && window.MoEngageVedantu.track_event('Signup_Complete', { 529 'grade': (!!resp && !!resp.studentInfo && resp.studentInfo.grade) || null, 530 'board': (!!resp && !!resp.studentInfo && resp.studentInfo.board) || null, 531 'target': (!!resp && !!resp.studentInfo && resp.studentInfo.target) || null, 532 'examTargets': (!!resp && !!resp.studentInfo && resp.studentInfo.examTargets) || null 533 }); 534 } 535 } 536 catch (err) { 537 console.log("Error while sending Moengage event", err) 538 } 539 setUserEntityMoEngage(data); 540 } 541 542 function setUserEntityMoEngage(e, isSessionData) { 543 if ((!!e && !!e.detail) || isSessionData) { 544 545 try { 546 var userData = !!isSessionData ? e : e.detail; 547 userData.userId = userData.userId || userData.id || (userData.user && userData.user.userId) || (userData.user && userData.user.id); 548 if (!!userData.userId) { 549 var userAttributeLSArray = []; 550 if (!!moengageStoredUserId && moengageStoredUserId != userData.userId) { 551 userAttributeLSArray.push({ type: "uuui", value: userData.userId }) 552 } else { 553 userAttributeLSArray.push({ type: "auui", value: userData.userId }) 554 } 555 556 userAttributeLSArray.push({ type: "afn", value: trimTheUAValue(userData.firstName) }); 557 userAttributeLSArray.push({ type: "aln", value: trimTheUAValue(userData.lastName) }); 558 userAttributeLSArray.push({ type: "am", value: String(!!userData.phoneCode ? userData.phoneCode : "91") + userData.contactNumber }); 559 560 var userMainData = null; 561 if (userData.user && (userData.user.userId || userData.user.id)) { 562 userMainData = userData.user; 563 } else { 564 userMainData = userData; 565 } 566 567 if (userMainData.email) { 568 userAttributeLSArray.push({ type: "ae", value: trimTheUAValue(userMainData.email) }); 569 } 570 userAttributeLSArray.push({ type: "aua", name: "grade", value: userMainData.grade || (userMainData.studentInfo && userMainData.studentInfo.grade) || null }); 571 userAttributeLSArray.push({ type: "aua", name: "board", value: userMainData.board || (userMainData.studentInfo && userMainData.studentInfo.board) || null }); 572 userAttributeLSArray.push({ type: "aua", name: "target", value: userMainData.target || (userMainData.studentInfo && userMainData.studentInfo.target) || null }); 573 userAttributeLSArray.push({ type: "aua", name: "examTargets", value: trimTheUAValue(userMainData.examTargets || (userMainData.studentInfo && userMainData.studentInfo.examTargets)) || null }); 574 // userAttributeLSArray.push({ type: "aua", name: "isContactNumberVerified", value: userMainData.isContactNumberVerified || null }); 575 // userAttributeLSArray.push({type:"aua",name:"isContactNumberDND",value:userMainData.isContactNumberDND || null}); 576 // userAttributeLSArray.push({type:"aua",name:"referralCode",value:userMainData.referralCode || null}); 577 // if (isAVSKPage) { 578 // userAttributeLSArray.push({ type: "aua", name: "utm_source", value: userMainData.utm_source || null }); 579 // userAttributeLSArray.push({ type: "aua", name: "utm_medium", value: userMainData.utm_medium || null }); 580 // userAttributeLSArray.push({ type: "aua", name: "utm_campaign", value: userMainData.utm_campaign || null }); 581 // userAttributeLSArray.push({ type: "aua", name: "utm_term", value: userMainData.utm_term || null }); 582 // userAttributeLSArray.push({ type: "aua", name: "utm_content", value: userMainData.utm_content || null }); 583 // } 584 // userAttributeLSArray.push({ type: "aua", name: "locationInfo", value: userMainData.locationInfo || null }); 585 // userAttributeLSArray.push({ type: "aua", name: "role", value: userMainData.role || null }); 586 // userAttributeLSArray.push({ type: "aua", name: "phoneCode", value: userMainData.phoneCode || null }); 587 // userAttributeLSArray.push({ type: "aua", name: "isEmailVerified", value: userMainData.isEmailVerified || null }); 588 userAttributeLSArray.push({ type: "aua", name: "parentEmails", value: trimTheUAValue(userMainData.parentEmails) || null }); 589 userAttributeLSArray.push({ type: "aua", name: "parentContactNumber", value: (userMainData.studentInfo && (userMainData.studentInfo.parentContactNo || userMainData.studentInfo.parentContactNumbers)) || null }); 590 userAttributeLSArray.push({ type: "aua", name: "parentFirstName", value: (userMainData.studentInfo && trimTheUAValue(userMainData.studentInfo.parentFirstName)) || null }); 591 // userAttributeLSArray.push({ type: "aua", name: "parentLastName", value: (userMainData.studentInfo && (userMainData.studentInfo.parentLastName)) || null }); 592 593 !!window && !!window.localStorage && window.localStorage.setItem(USER_ATTRIBUTE_STORAGE_KEY, window.JSON.stringify(userAttributeLSArray)); 594 localUAData = userAttributeLSArray; 595 596 checkPaidUserOrNot(); 597 syncUserAttributesInit(); 598 } 599 } 600 catch (err) { 601 console.log("moengage something went wrong " + err); 602 } 603 } 604 }; 605 606 window.removeEventListener('normal-signup', handleSignUpEvent, true); 607 window.removeEventListener('normal-login', handleLogin, true); 608 window.removeEventListener('social-signup', handleSignUpEvent, true); 609 window.removeEventListener('social-login', handleLogin, true); 610 window.removeEventListener('update-userdata', handleUpdateData, true); 611 window.removeEventListener('vedantu-logout', destroyUserEntity
611MoEngage, true); 612 613 window.addEventListener('normal-signup', handleSignUpEvent, true); 614 window.addEventListener('normal-login', handleLogin, true); 615 window.addEventListener('social-signup', handleSignUpEvent, true); 616 window.addEventListener('social-login', handleLogin, true); 617 window.addEventListener('update-userdata', handleUpdateData, true); 618 window.addEventListener('vedantu-logout', destroyUserEntityMoEngage, true); 619 620 621 isMoELoaded = true; 622 syncUserAttributesInit(); 623 syncDataInit(); 624 var MoEngageEvent = new CustomEvent('VED-MOE-LOADED'); 625 window.dispatchEvent(MoEngageEvent); 626 }; 627 }); 628 629 630 (function (i, s, o, g, r, a, m, n) { i.moengage_object = r; t = {}; q = function (f) { return function () { (i.moengage_q = i.moengage_q || []).push({ f: f, a: arguments }) } }; f = ['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', 'moe_events', 'call_web_push', 'track', 'location_type_attribute'], h = { onsite: ["getData", "registerCallback"] }; for (k in f) { t[f[k]] = q(f[k]) } for (k in h) for (l in h[k]) { null == t[k] && (t[k] = {}), t[k][h[k][l]] = q(k + "." + h[k][l]) } a = s.createElement(o); m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m); i.moe = i.moe || function () { n = arguments[0]; return t }; a.onload = function () { if (n) { i[r] = moe(n) } } })(window, document, 'script', 'https://cdn.moengage.com/webpush/moe_webSdk.min.latest.js', 'Moengage'); 631 Moengage = moe({ 632 app_id: MOENGAGE_APP_ID, 633 debug_logs: isProductionDebugLog 634 }); 635 }; 636 }; 637 638 var syncDataInit = function () { 639 /** 640 * @description- Main MoEngage function for syncing events to Moengage. 641 * @returns {undefined} 642 */ 643 localAnalyticsData = !!localAnalyticsData && !!localAnalyticsData.length ? localAnalyticsData : []; 644 if (!dataSynchedOnPageLoad) { 645 var getlocalAnalyticsDataInfo = getData() || []; 646 getlocalAnalyticsDataInfo.forEach(function (ele) { 647 localAnalyticsData.push(ele); 648 }) 649 dataSynchedOnPageLoad = true; 650 }; 651 if (!!timerObj) { 652 window.clearInterval(timerObj) 653 }; 654 synchDataToMoEngage(); 655 timerObj = setInterval(function () { 656 synchDataToMoEngage(); 657 }, SYNCH_TIME); 658 }; 659 660 var syncUserAttributesInit = function () { 661 /** 662 * @description- Main MoEngage function for syncing user attributes to Moengage. 663 * @returns {undefined} 664 */ 665 if (!uaSynchedOnPageLoad) { 666 var getUADataInfo = getUAData() || []; 667 getUADataInfo.forEach(function (ele) { 668 localUAData.push(ele); 669 }) 670 uaSynchedOnPageLoad = true; 671 }; 672 if (!!uaTimerObj) { 673 window.clearInterval(uaTimerObj) 674 }; 675 syncUserAttributesToMoEngage(); 676 uaTimerObj = setInterval(function () { 677 syncUserAttributesToMoEngage(); 678 }, UA_SYNCH_TIME); 679 }; 680 681 var init = function () { 682 MoEngageInitSetup(); 683 }; 684 685 init(); 686 687 return { 688 addUserAttribute: addUserAttribute, 689 track_event: addData 690 }; 691 } 692 window.MoEngageVedantu = MoEngageVedantu(); 693})(document, window);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.