1// const getOrigin = () => new URL(document.currentScript.src).origin; 2 3const auwUserEvent = { 4 5 url: "https://handler.amarujala.com", 6 7 // ! TO SET COOKIE DATA 8 createCookie: function (cookieName, cookieValue, minutesToExpire) { 9 const date = new Date(); 10 date.setTime(date.getTime() + (minutesToExpire * 60 * 1000)); 11 document.cookie = `${cookieName}=${cookieValue}; expires=${date.toGMTString()}; path=/;`; 12 }, 13 14 // ! TO GET COOKIE DATA 15 getCookie: function (cookieName) { 16 const name = `${cookieName}=`; 17 const allCookieArray = document.cookie.split(";"); 18 for (let i = 0; i < allCookieArray.length; i += 1) { 19 const temp = allCookieArray[i].trim(); 20 if (temp.indexOf(name) === 0) { 21 return temp.substring(name.length, temp.length); 22 } 23 } 24 return ""; 25 }, 26 27 setCookieExpireEndOfDay: function (name, value) { 28 const now = new Date(); 29 const expire = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999); 30 document.cookie = `${name}=${value}; expires=${expire.toGMTString()}; path=/`; 31 }, 32 33 setCookieExpireEndOfMonth: function (name, value) { 34 const now = new Date(); 35 const endOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59, 999); 36 document.cookie = `${name}=${value}; expires=${endOfMonth.toGMTString()}; path=/`; 37 }, 38 39 // ! TO SET INITIAL TIME IN COOKIE 40 originTime: function () { 41 const initialTime = new Date().getTime(); 42 sessionStorage.setItem("auw_initialTime", initialTime); 43 }, 44 45 // ! TO GENERATE RANDOM ID FOR SESSION AND GUEST USER 46 generateId: function (length) { 47 let result = ""; 48 const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 49 const charactersLength = characters.length; 50 for (let i = 0; i < length; i += 1) { 51 result += characters.charAt(Math.floor(Math.random() * charactersLength)); 52 } 53 return result; 54 }, 55 56 // ! SET SESSION ID FOR USER EVENTS 57 setSessionId: function () { 58 if (!sessionStorage.getItem("auw_session_id")) { 59 sessionStorage.setItem("auw_session_id", auwUserEvent.generateId(25)); 60 if (localStorage.getItem("_recuih")) { 61 let data = JSON.parse(localStorage.getItem("_recuih")); 62 if (data["session_count"]) { 63 let session_count = parseInt(data["session_count"]) + 1; 64 data["session_count"] = session_count; 65 localStorage.setItem("_recuih", JSON.stringify(data)); 66 return; 67 } 68 data["session_count"] = 1; 69 localStorage.setItem("_recuih", JSON.stringify(data)); 70 } 71 } 72 }, 73 74 // ! TO CHECK IF GUEST_ID IS PRESENT OR NOT... 75 guestId: function () { 76 if (!auwUserEvent.getCookie("auw_guest_id")) { 77 auwUserEvent.createCookie("auw_guest_id", auwUserEvent.generateId(20), (365 * 24 * 60)); 78 } 79 }, 80 81 // ! TO CHECK FOR ENTITY TYPE 82 entityType: function () { 83 if (typeof _auw_page_detail !== "undefined") { 84 const template = (_auw_page_detail?.template) ? _auw_page_detail?.template : null; 85 return template; 86 }; 87 return null; 88 }, 89 90 // ! TO CHECK FOR ENTITY ID 91 entityId: function () { 92 if (typeof _auw_page_detail !== "undefined" && _auw_page_detail) { 93 if (typeof _auw_page_detail.analytics != "undefined" && typeof _auw_page_detail.analytics.id != "undefined" && _auw_page_detail.analytics.id) { 94 return _auw_page_detail.analytics.id; 95 } 96 } 97 return null; 98 }, 99 100 // ! TO CHECK USER TYPE 101 userType: function () { 102 if (typeof _auw_page_detail !== "undefined") { 103 const user = (_auw_page_detail?.user_type) ? _auw_page_detail?.user_type : null; 104 return user; 105 }; 106 return null; 107 }, 108 109 // ! PAGE CATEGORY DETAILS 110 category: function () { 111 if (typeof _auw_page_detail !== "undefined") { 112 const category = (_auw_page_detail?.category) ? _auw_page_detail?.category : null; 113 return category; 114 }; 115 return null; 116 }, 117 118 subCategory: function () { 119 if (typeof _auw_page_detail !== "undefined") { 120 const sub_category = (_auw_page_detail?.sub_category) ? _auw_page_detail?.sub_category : null; 121 return sub_category; 122 }; 123 return null; 124 }, 125 126 // ! CITY DETAILS
127 locationDetails: function () { 128 if (typeof _auw_page_detail != "undefined" && _auw_page_detail) { 129 if (typeof _auw_page_detail.city != "undefined" && _auw_page_detail.city) { 130 return _auw_page_detail.city; 131 } 132 if (typeof _auw_page_detail.hyper != "undefined" && _auw_page_detail.hyper) { 133 return _auw_page_detail.hyper; 134 } 135 return _auw_page_detail.state; 136 } 137 return null; 138 }, 139 140 locationCity: function () { 141 if (typeof _auw_page_detail !== "undefined") { 142 if (_auw_page_detail?.city) { 143 return _auw_page_detail.city; 144 } 145 }; 146 return null; 147 }, 148 149 locationState: function () { 150 if (typeof _auw_page_detail !== "undefined") { 151 if (_auw_page_detail?.state) { 152 return _auw_page_detail.state; 153 } 154 }; 155 return null; 156 }, 157 158 locationHyper: function () { 159 if (typeof _auw_page_detail !== "undefined") { 160 if (_auw_page_detail.hyper) { 161 return _auw_page_detail.hyper; 162 } 163 }; 164 return null; 165 }, 166 167 //! story author details 168 authorDetails: function () { 169 if (typeof _auw_page_detail != "undefined" && _auw_page_detail) { 170 if (typeof _auw_page_detail.story_writer != "undefined" && _auw_page_detail.story_writer) { 171 return _auw_page_detail.story_writer; 172 } 173 } 174 return null; 175 }, 176 177 //! story author details 178 contentPartners: function () { 179 if (typeof _auw_page_detail != "undefined" && _auw_page_detail) { 180 if (typeof _auw_page_detail.content_partner != "undefined" && _auw_page_detail.content_partner) { 181 return _auw_page_detail.content_partner; 182 } 183 } 184 return null; 185 }, 186 187 source: function () { 188 if (typeof _auw_page_detail != "undefined" && _auw_page_detail) { 189 if (typeof _auw_page_detail.request_client != "undefined" && _auw_page_detail.request_client) { 190 return _auw_page_detail.request_client; 191 } 192 } 193 return null; 194 }, 195 196 tags: function () { 197 if (typeof _auw_page_detail != "undefined" && _auw_page_detail) { 198 if (typeof _auw_page_detail.tags != "undefined" && _auw_page_detail.tags) { 199 return _auw_page_detail.tags; 200 } 201 } 202 return null; 203 }, 204 205 slugFormatter: function (value) { 206 let temp_slug = value.split("/"); 207 temp_slug = temp_slug[temp_slug.length - 1]; 208 temp_slug = temp_slug.split("?"); 209 return temp_slug[0]; 210 }, 211 212 incrementStoryCount: function () { 213 const story_count = auwUserEvent.getCookie("daily_story_view"); 214 if (story_count) { 215 const d_count = parseInt(story_count) + 1; 216 auwUserEvent.setCookieExpireEndOfDay("daily_story_view", d_count); 217 } else { 218 auwUserEvent.setCookieExpireEndOfDay("daily_story_view", 1); 219 let monthly_count = auwUserEvent.getCookie("monthly_story_view"); 220 if (monthly_count) { 221 if (!localStorage.getItem("msv")) { 222 let cookieString = `monthly_story_view=; expires=${new Date(0).toGMTString()}; path=/`; 223 document.cookie = cookieString; 224 monthly_count = 0; 225 localStorage.setItem("msv", true); 226 }; 227 const m_count = parseInt(monthly_count) + 1; 228 auwUserEvent.setCookieExpireEndOfMonth("monthly_story_view", m_count); 229 } else { 230 auwUserEvent.setCookieExpireEndOfMonth("monthly_story_view", 1); 231 }; 232 }; 233 }, 234 235 urlFormatter: function () { 236 const queryObject = (value) => Object.fromEntries(new URL(value).searchParams); 237 return { 238 url: window?.location?.href || null, 239 slug: (window?.location?.pathname) ? window?.location?.pathname?.split("/").pop() : null, 240 fullSlug: window?.location?.pathname || null, 241 query: window?.location?.search || null, 242 queryObject: queryObject(window?.location?.href) 243 }; 244 }, 245 246 unitName: function () { 247 if (typeof _auw_page_detail !== "undefined") { 248 const user = (_auw_page_detail?.unit_name) ? _auw_page_detail?.unit_name : null; 249 return user; 250 }; 251 return null; 252 }, 253 254 screenName: function () { 255 const source = typeof _auw_page_detail !== "undefined" ? _auw_page_detail?.analytics?.user_source : null; 256 if (!source) return null; 257 return `${source.replaceAll("-", "_")}_page`; 258 }, 259 260 videoDetails: function () { 261 const video_duration = (typeof _auw_page_detail !== "undefined") ? _auw_page_detail?.video_duration : null; 262 return video_duration || null; 263 }, 264 265 experiments: function () { 266 const exp = (typeof _auw_page_detail !== "undefined") ? _auw_page_detail?.experiments : null; 267 return exp || []; 268 }, 269 270 setAcqSource: function () { 271 const acqSources = auwUserEvent.screenName(); 272 const acqSubSource = auwUserEvent.entityId(); 273 sessionStorage.setItem("acqSource", acqSources); 274 sessionStorage.setItem("acqSubSource", acqSubSource); 275 }, 276 277 eventData: function () { 278 const data = { 279 landing_page: window.location.href, 280 referrer: document.referrer, 281 screen_height: window.screen.height, 282 screen_width: window.screen.width, 283 user_agent: window.navigator.userAgent, 284 entity_type: auwUserEvent.entityType(), 285 entity_id: auwUserEvent.entityId(), 286 user_id: auwUserEvent.getCookie("_raidu"), 287 parent_id: auwUserEvent.getCookie("auw_parent_id"), 288 session_id: sessionStorage.getItem("auw_session_id"),
289 user_type: auwUserEvent.userType(), 290 location: auwUserEvent.locationDetails(), 291 category: auwUserEvent.category(), 292 sub_category: auwUserEvent.subCategory(), 293 content_partner: auwUserEvent.contentPartners(), 294 story_writer: auwUserEvent.authorDetails(), 295 source: auwUserEvent.source(), 296 guest_id: auwUserEvent.getCookie("auw_guest_id"), 297 personalisation_location: JSON.parse(localStorage.getItem("personalisation_location")), 298 event_timestamp: Date.now(), 299 tags: auwUserEvent.tags(), 300 city: auwUserEvent.locationCity(), 301 state: auwUserEvent.locationState(), 302 hyper: auwUserEvent.locationHyper(), 303 screenName: auwUserEvent.screenName(), 304 unitName: auwUserEvent.unitName(), 305 experiments: auwUserEvent.experiments(), 306 acqSource: sessionStorage.getItem("acqSource"), 307 acqSubSource: sessionStorage.getItem("acqSubSource") 308 }; 309 return data; 310 }, 311 312 appPayload: function () { 313 const payload = { 314 url: this.urlFormatter().url, 315 fullSlug: this.urlFormatter().fullSlug, 316 slug: this.urlFormatter().slug, 317 query: this.urlFormatter().query, 318 referrer: document.referrer, 319 category: this.category(), 320 subCategory: this.subCategory(), 321 locationState: this.locationState(), 322 locationCity: this.locationCity(), 323 unitName: this.unitName(), 324 userType: this.userType(), 325 experiments: this.experiments() 326 }; 327 return payload; 328 }, 329 330 // ! FETCH FUNCTION TO POST DATA 331 fetch: function (data) { 332 if (data == null) { 333 return; 334 } 335 fetch(`${auwUserEvent.url}/user/event`, { 336 method: "POST", 337 headers: { 338 "Content-Type": "application/json", 339 }, 340 body: JSON.stringify(data), 341 }).then(req => req.json()).then(response => auwUserEvent.createCookie("auw_parent_id", response.id)) 342 .catch(error => console.error("Error:", error)); 343 }, 344 345 customEvent: function (event, value) { 346 if (auwUserEvent.clientCheck()) { 347 let temp = auwUserEvent.appPayload(); 348 window?.MyJSClient?.webview_events_cdp(event, temp); 349 } else { 350 const data = { 351 userData: auwUserEvent.eventData(), 352 event_type: event, 353 event_value: value, 354 }; 355 auwUserEvent.fetch(data); 356 }; 357 }, 358 359 360 // ! TO SEND REQUEST TO SERVER 361 loadTime: function () { 362 const client = this.urlFormatter()?.queryObject?.client_new; 363 const slug = this.urlFormatter()?.slug; 364 const template = auwUserEvent.screenName(); 365 366 if (client === "au_revamp") { 367 const app_version = window?.MyJSClient?.getAndroidAppVersion(); 368 let value = parseInt(app_version?.split(".").pop()); 369 if (value > 32) { 370 window?.MyJSClient?.webview_events_cdp("PAGE_VIEW", this.appPayload()); 371 if (slug === "success") { 372 let selectedPlan = JSON.parse(sessionStorage.getItem("selectedPlan")) || null; 373 let couponValue = sessionStorage.getItem("couponCode") || null; 374 let finalValue = sessionStorage.getItem("value") || null; 375 376 const url = new URL(window?.location?.href); 377 const orderId = url.searchParams.get("order_id"); 378 379 let temp = auwUserEvent.appPayload(); 380 381 temp["coupon"] = couponValue; 382 temp["planId"] = selectedPlan[2] || null; 383 temp["plan"] = selectedPlan[1] || null; 384 temp["price"] = selectedPlan[0] || null; 385 temp["currency"] = selectedPlan[3] || null; 386 temp["isDefault"] = selectedPlan[4] || true; 387 temp["value"] = parseFloat(finalValue); 388 temp["orderId"] = orderId; 389 // temp["paymentMethod"] = typeof scart !== "undefined" ? scart?.transaction?.payment_details?.payment_method || scart?.transaction?.payment_details?.PG_TYPE : '' 390 window?.MyJSClient?.webview_events_cdp("BUYS_PREMIUM_SUBSCRIPTION", temp); 391 }; 392 393 if (slug === "failure") { 394 let selectedPlan = JSON.parse(sessionStorage.getItem("selectedPlan")) || null; 395 let couponValue = sessionStorage.getItem("couponCode") || null; 396 let finalValue = sessionStorage.getItem("value") || null; 397 398 const url = new URL(window?.location?.href); 399 const orderId = url.searchParams.get("order_id"); 400
401 let temp = auwUserEvent.appPayload(); 402 403 temp["coupon"] = couponValue; 404 temp["planId"] = selectedPlan[2] || null; 405 temp["plan"] = selectedPlan[1] || null; 406 temp["price"] = selectedPlan[0] || null; 407 temp["currency"] = selectedPlan[3] || null; 408 temp["isDefault"] = selectedPlan[4] || true; 409 temp["value"] = parseFloat(finalValue); 410 temp["orderId"] = orderId; 411 // temp["paymentMethod"] = typeof scart !== "undefined" ? scart?.transaction?.payment_details?.payment_method || scart?.transaction?.payment_details?.PG_TYPE : ''; 412 // temp["failureReason"] = typeof scart !== "undefined" ? scart.transaction?.payment_details?.error_Message : ''; 413 414 window?.MyJSClient?.webview_events_cdp("PURCHASE_FAILED", temp); 415 }; 416 } else { 417 const data = { 418 userData: auwUserEvent.eventData(), 419 event_type: "views", 420 event_value: auwUserEvent.entityId(), 421 }; 422 auwUserEvent.fetch(data); 423 }; 424 } else { 425 const data = { 426 userData: auwUserEvent.eventData(), 427 event_type: "views", 428 event_value: auwUserEvent.entityId(), 429 }; 430 auwUserEvent.fetch(data); 431 432 if (slug === "success") { 433 const url = new URL(window?.location?.href); 434 const orderId = url.searchParams.get("order_id"); 435 const data = { 436 userData: auwUserEvent.eventData(), 437 event_type: "BUYS_PREMIUM_SUBSCRIPTION", 438 event_value: JSON.parse(sessionStorage.getItem("selectedPlan")) || [], 439 coupon: sessionStorage.getItem("couponCode") || null, 440 value: sessionStorage.getItem("value") ? parseFloat(sessionStorage.getItem("value")) : null, 441 orderId: orderId, 442 // paymentMethod: typeof scart !== "undefined" ? scart?.transaction?.payment_details?.payment_method || scart?.transaction?.payment_details?.PG_TYPE : '', 443 }; 444 auwUserEvent.fetch(data); 445 }; 446 if (slug === "failure") { 447 const url = new URL(window?.location?.href); 448 const orderId = url.searchParams.get("order_id"); 449 450 const data = { 451 userData: auwUserEvent.eventData(), 452 event_type: "PURCHASE_FAILED", 453 event_value: JSON.parse(sessionStorage.getItem("selectedPlan")) || [], 454 coupon: sessionStorage.getItem("couponCode") || null, 455 value: sessionStorage.getItem("value") ? parseFloat(sessionStorage.getItem("value")) : null, 456 orderId: orderId, 457 // paymentMethod: typeof scart !== "undefined" ? scart?.transaction?.payment_details?.payment_method || scart?.transaction?.payment_details?.PG_TYPE : '', 458 // failureReason: typeof scart !== "undefined" ? scart.transaction?.payment_details?.error_Message : '', 459 }; 460 auwUserEvent.fetch(data); 461 }; 462 }; 463 464 let result = JSON.parse(localStorage.getItem("_recuih")); 465 466 let category = (auwUserEvent.category()) ? auwUserEvent.category() : null; 467 let location = (auwUserEvent.locationDetails()) ? auwUserEvent.locationDetails() : null; 468 let page = (auwUserEvent.entityType()) ? auwUserEvent.entityType() : null; 469 let story_id = (auwUserEvent.entityId()) ? auwUserEvent.entityId() : null; 470 471 if (!result.categories) { 472 result["categories"] = {}; 473 result["locations"] = {}; 474 result["pages"] = {}; 475 result["read_stories"] = []; 476 result["recent_entity_visited"] = {}; 477 478 if (category) { 479 result.categories[category] = 1; 480 result.recent_entity_visited["entity_type"] = "category"; 481 result.recent_entity_visited["entity_slug"] = category; 482 }; 483 if (page) { 484 result.pages[page] = 1; 485 }; 486 if (location) { 487 result.locations[location] = 1; 488 result.recent_entity_visited["entity_type"] = "location"; 489 result.recent_entity_visited["entity_slug"] = location; 490 }; 491 if (story_id) { 492 result.read_stories.push(story_id); 493 } 494 localStorage.setItem("_recuih", JSON.stringify(result)) 495 return; 496 }; 497 if (page) { 498 if (result.pages[page]) { 499 result.pages[page] += 1; 500 } else { 501 result.pages[page] = 1; 502 } 503 } 504 505 if (category) { 506 if (result.categories[category]) { 507 result.categories[category] += 1; 508 result["recent_entity_visited"] = {}; 509 result["recent_entity_visited"]["entity_type"] = "category"; 510 result["recent_entity_visited"]["entity_slug"] = category; 511 } else { 512 result.categories[category] = 1; 513 result["recent_entity_visited"] = {}; 514 result["recent_entity_visited"]["entity_type"] = "category"; 515 result["recent_entity_visited"]["entity_slug"] = category; 516 } 517 } 518 519 if (location) { 520 if (result.locations[location]) { 521 result.locations[location] += 1; 522 result["recent_entity_visited"] = {}; 523 result["recent_entity_visited"]["entity_type"] = "location"; 524 result["recent_entity_visited"]["entity_slug"] = location; 525 } else { 526 result.locations[location] = 1; 527 result["recent_entity_visited"] = {}; 528 result["recent_entity_visited"]["entity_type"] = "location"; 529 result["recent_entity_visited"]["entity_slug"] = location; 530 } 531 }; 532 533 if (story_id) { 534 if (result.read_stories.length < 30) { 535 if (!result.read_stories.includes(story_id)) { 536 result.read_stories.push(story_id); 537 } 538 } else { 539 if (!result.read_stories.includes(story_id)) { 540 result.read_stories.shift(); 541 result.read_stories.push(story_id); 542 } 543 } 544 } 545 result["sun_shine"] = auwUserEvent.getCookie("sun_sign"); 546 localStorage.setItem("_recuih", JSON.stringify(result)); 547 }, 548 549 customEventType: function (eventType, eventValue, entityType, entity
549Id) { 550 const data = { 551 userData: auwUserEvent.eventData(), 552 entity_type: entityType, 553 entity_id: entityId, 554 event_type: eventType, 555 event_value: eventValue, 556 }; 557 auwUserEvent.fetch(data); 558 }, 559 560 readTime: function (scroll_depth) { 561 562 let t1 = sessionStorage.getItem("auw_initialTime"); 563 t1 = parseInt(t1); 564 565 let t2 = new Date().getTime(); 566 t2 = parseInt(t2); 567 568 let time = Math.floor((t2 - t1) / 1000); 569 570 sessionStorage.setItem("auw_initialTime", t2); 571 sessionStorage.setItem("scroll_depth", scroll_depth); 572 573 let t3 = parseInt(sessionStorage.getItem("readTime")) + time; 574 sessionStorage.setItem("readTime", t3); 575 576 const client = auwUserEvent.urlFormatter()?.queryObject?.client_new; 577 if (client === "au_revamp") { 578 const app_version = window?.MyJSClient?.getAndroidAppVersion(); 579 let value = parseInt(app_version?.split(".").pop()); 580 if (value > 32) { 581 const payload = this.appPayload(); 582 payload["pageHeight"] = $(document).height(); 583 payload["scrollHeight"] = $(window).scrollTop(); 584 payload["scroll_depth"] = parseInt(scroll_depth); 585 payload["event_value"] = parseInt(sessionStorage.getItem("readTime")); 586 payload["storyId"] = auwUserEvent.entityId(); 587 588 window?.MyJSClient?.webview_events_cdp("READ_TIME", payload); 589 590 if (scroll_depth === 50 || scroll_depth === 80) { 591 window?.MyJSClient?.webview_events_cdp(`STORY_READ_${scroll_depth}`, payload); 592 }; 593 } else { 594 const data = { 595 userData: auwUserEvent.eventData(), 596 event_type: "readtime", 597 event_value: parseInt(sessionStorage.getItem("readTime")), 598 page_height: $(document).height(), 599 scroll_height: $(window).scrollTop(), 600 scroll_depth: parseInt(scroll_depth) 601 }; 602 auwUserEvent.fetch(data); 603 }; 604 } else { 605 const data = { 606 userData: auwUserEvent.eventData(), 607 event_type: "readtime", 608 event_value: parseInt(sessionStorage.getItem("readTime")), 609 page_height: $(document).height(), 610 scroll_height: $(window).scrollTop(), 611 scroll_depth: parseInt(scroll_depth) 612 }; 613 auwUserEvent.fetch(data); 614 }; 615 }, 616 617 eventScroll: function () { 618 let current_time = new Date().getTime(); 619 sessionStorage.setItem("auw_initialTime", current_time); 620 sessionStorage.setItem("readTime", 0); 621 sessionStorage.setItem("scroll_depth", 0); 622 623 let scrollTracker = { "10": 0, "25": 0, "50": 0, "75": 0, "90": 0, "100": 0 }; 624 625 let template = auwUserEvent.entityType(); 626 if (template == "story" || template == "feature-story" || template == "photo-gallery") { 627 return; 628 } else { 629 $(window).scroll(function (e) { 630 let scrollTop = $(window).scrollTop(); 631 let docHeight = $(document).height(); 632 let winHeight = $(window).height(); 633 let scrollPercent = (scrollTop) / (docHeight - winHeight); 634 let percentScrolled = Math.round(scrollPercent * 100); 635 636 if (percentScrolled >= 10 && percentScrolled < 25) { 637 if (scrollTracker["10"] === 0) { 638 scrollTracker["10"] = 1; 639 auwUserEvent.readTime(10); 640 } 641 } else if (percentScrolled >= 25 && percentScrolled < 50) { 642 if (scrollTracker["25"] === 0) { 643 scrollTracker["25"] = 1; 644 auwUserEvent.readTime(25); 645 } 646 } else if (percentScrolled >= 50 && percentScrolled < 75) { 647 if (scrollTracker["50"] === 0) { 648 scrollTracker["50"] = 1; 649 auwUserEvent.readTime(50); 650 } 651 } else if (percentScrolled >= 75 && percentScrolled < 90) { 652 if (scrollTracker["75"] === 0) { 653 scrollTracker["75"] = 1; 654 auwUserEvent.readTime(75); 655 } 656 } else if (percentScrolled >= 90 && percentScrolled < 100) { 657 if (scrollTracker["90"] === 0) { 658 scrollTracker["90"] = 1; 659 auwUserEvent.readTime(90); 660 } 661 } else if (percentScrolled === 100) { 662 if (scrollTracker["100"] === 0) { 663 scrollTracker["100"] = 1; 664 auwUserEvent.readTime(100); 665 } 666 } 667 }); 668 } 669 }, 670 671 672 eventBookmark: function () { 673 $(document).ready(function () { 674 $(".auw-bookmark").on("click", function () { 675 const id = $(this).attr("data-id"); 676 const data = { 677 userData: auwUserEvent.eventData(), 678 event_type: "bookmark", 679 event_value: id, 680 }; 681 auwUserEvent.fetch(data); 682 let result = JSON.parse(localStorage.getItem("_recuih")); 683 if (!result.bookmark_stories) { 684 result.bookmark_stories = [auwUserEvent.entityId()]; 685 localStorage.setItem("_recuih", JSON.stringify(result)); 686 return; 687 } 688 if (result["bookmark_stories"].length > 30) { 689 if (!result["bookmark_stories"].includes(auwUserEvent.entityId())) { 690 result["bookmark_stories"].shift(); 691 result["bookmark_stories"].push(auwUserEvent.entityId()); 692 } 693 } else { 694 if (!result["bookmark_stories"].includes(auwUserEvent.entityId())) { 695 result["bookmark_stories"].push(auwUserEvent.entityId()); 696 } 697 } 698 localStorage.setItem("_recuih", JSON.stringify(result)); 699 }); 700 }); 701 }, 702 703 eventShare: function () { 704 let template = typeof _auw_page_detail !== "undefined" ? _auw_page_detail?.template : null; 705 if (template === "videoshots") return; 706 $(document).ready(function () { 707 $(".auw_event_share").on("click", function () { 708 const data = { 709 userData: auwUserEvent.eventData(), 710 event_type: "share", 711 event_value: $(this).attr("share-type"), 712 }; 713 auwUserEvent.fetch(data); 714 let result = JSON.parse(localStorage.getItem("_recuih")); 715 if (!result.story_share_details) { 716 result["story_share_details"] = [];
717 let temp_share_type = { 718 "shared_type": $(this).attr("share-type"), 719 "shared_type_count": 1, 720 "stories_id": [auwUserEvent.entityId()] 721 }; 722 result["story_share_details"].push(temp_share_type); 723 localStorage.setItem("_recuih", JSON.stringify(result)); 724 return; 725 }; 726 let type = $(this).attr("share-type"); 727 let index = result["story_share_details"].findIndex(function (ele) { 728 console.log(ele.shared_type); 729 return ele.shared_type === type 730 }); 731 if (index === -1) { 732 let temp_share_type = { 733 "shared_type": $(this).attr("share-type"), 734 "shared_type_count": 1, 735 "stories_id": [auwUserEvent.entityId()] 736 }; 737 result["story_share_details"].push(temp_share_type); 738 } else { 739 result["story_share_details"][index]["shared_type_count"] += 1; 740 if (result["story_share_details"][index]["stories_id"].length > 30) { 741 if (!result["story_share_details"][index]["stories_id"].includes(auwUserEvent.entityId())) { 742 result["story_share_details"][index]["stories_id"].shift(); 743 result["story_share_details"][index]["stories_id"].push(auwUserEvent.entityId()); 744 } 745 } else { 746 if (!result["story_share_details"][index]["stories_id"].includes(auwUserEvent.entityId())) { 747 result["story_share_details"][index]["stories_id"].push(auwUserEvent.entityId()); 748 } 749 } 750 } 751 localStorage.setItem("_recuih", JSON.stringify(result)); 752 }); 753 }); 754 }, 755 756 _recuih: function () { 757 if (localStorage.getItem("_recuih")) { 758 let result = JSON.parse(localStorage.getItem("_recuih")); 759 let currentRaidu = auwUserEvent.getCookie("_raidu") || ""; 760 let storedUserId = result["user_id"] || ""; 761 762 if (storedUserId === currentRaidu) { 763 result["user_id"] = currentRaidu; 764 localStorage.setItem("_recuih", JSON.stringify(result)); 765 } else { 766 if (result.user_id?.length === 0) { 767 result["user_id"] = auwUserEvent.getCookie("_raidu"); 768 localStorage.setItem("_recuih", JSON.stringify(result)); 769 } else { 770 const result = {}; 771 localStorage.setItem("_recuih", JSON.stringify(result)); 772 const data = { 773 user_type: auwUserEvent.userType(), 774 guest_id: auwUserEvent.getCookie("auw_guest_id"), 775 user_id: auwUserEvent.getCookie("_raidu") 776 }; 777 localStorage.setItem("_recuih", JSON.stringify(data)); 778 } 779 } 780 } else { 781 const data = { 782 user_type: auwUserEvent.userType(), 783 guest_id: auwUserEvent.getCookie("auw_guest_id"), 784 user_id: auwUserEvent.getCookie("_raidu") 785 }; 786 localStorage.setItem("_recuih", JSON.stringify(data)); 787 } 788 }, 789 790 incrementSession: function () { 791 let flag = JSON.parse(localStorage.getItem("sflag")); 792 if (flag) { 793 return; 794 }; 795 let scount = JSON.parse(localStorage.getItem("_ul30d")); 796 if (scount) { 797 if (scount < 30) { 798 scount = parseInt(scount) + 1; 799 localStorage.setItem("_ul30d", JSON.stringify(scount)); 800 } 801 localStorage.setItem("sflag", true); 802 } else { 803 localStorage.setItem("_ul30d", 1); 804 localStorage.setItem("sflag", true); 805 }; 806 }, 807 808 datesAreOnSameDay: function () { 809 let first = new Date(); 810 let second = localStorage.getItem("preTime") ? new Date(localStorage.getItem("preTime")) : new Date(); 811 812 let a = first.getFullYear() === second.getFullYear(); 813 let b = first.getMonth() === second.getMonth(); 814 let c = first.getDate() === second.getDate(); 815 if (a && b && c) { 816 localStorage.setItem('preTime', first); 817 auwUserEvent.incrementSession(); 818 return true; 819 } 820 localStorage.setItem('preTime', first); 821 localStorage.setItem("sflag", false); 822 auwUserEvent.incrementSession(); 823 }, 824 825 setDailyStoryViewCount: function () { 826 let template = auwUserEvent.entityType(); 827 if (template == "story" || template == "feature-story" || template == "photo-gallery") { 828 auwUserEvent.incrementStoryCount(); 829 }; 830 }, 831 832 qualityReadTime: function () { 833 let template = typeof _auw_page_detail !== "undefined" ? _auw_page_detail.template : null; 834 if (template == "story" || template == "feature-story" || template == "photo-gallery" || template == "wiki" || template == "live" || template == "blog" || template == "video" || template == "videoshots") { 835 if (_auw_page_detail?.expected_read_time) { 836 let expected_time = parseInt(_auw_page_detail.expected_read_time) * 1000; 837 setTimeout(() => { 838 const client = this.urlFormatter()?.queryObject?.client_new; 839 if (client === "au_revamp") { 840 const app_version = window?.MyJSClient?.getAndroidAppVersion(); 841 let value = parseInt(app_version?.split(".").pop()); 842 if (value >= 32) { 843 const app_payload = this.appPayload(); 844 app_payload["event_value"] = true; 845 window?.MyJSClient?.webview_events_cdp("QUALITY_READ", app_payload); 846 } else { 847 const data = { 848 userData: auwUserEvent.eventData(), 849 event_type: "QUALITY_READ", 850 event_value: true 851 }; 852 auwUserEvent.fetch(data); 853 } 854 } else { 855 const data = { 856 userData: auwUserEvent.eventData(), 857 event_type: "QUALITY_READ", 858 event_value: true 859 }; 860 auwUserEvent.fetch(data); 861 }; 862 }, expected_time); 863 }; 864 }; 865 }, 866 867 storyLikeDisLike: function () { 868 let template = typeof _auw_page_detail !== "undefined" ? _auw_page_detail?.template : null; 869 if (template === "videoshots") { 870 $("a.like-button").on("click", function (e) { 871 const storyId = $(this).data("storyid"); 872 const isLiked = this.classList.contains("liked"); 873 const data = { 874 userData: auwUserEvent.eventData(), 875 event_type: isLiked ? "VIDEO_DISLIKE" : "VIDEO_LIKE", 876 event_value: storyId, 877 }; 878 auwUserEvent.fetch(data); 879 }); 880 }; 881 }, 882 883 authorFollowUnfollow: function () { 884 let template = typeof _auw_page_detail !== "undefined" ? _auw_page_detail?.template : null; 885 if (template === "videoshots") { 886 document.addEventListener('click', async (e) => { 887 const btn = e.target.closest('.followBtn'); 888 if (!btn) return; 889 const id = btn.dataset.entityId; 890 const isFollowing = btn.classList.contains('sel'); 891 const data = { 892 userData: auwUserEvent.eventData(), 893 event_type: isFollowing ? "VIDEO_AUTHOR_FOLLOWED" : "VIDEO_AUTHOR_UNFOLLOWED", 894 event_value: id, 895 }; 896 auwUserEvent.fetch(data); 897 }); 898 }; 899 }, 900
901 sharedClicked: function () { 902 document.querySelector('.sharingIconDv')?.addEventListener('click', function () { 903 const data = { 904 userData: auwUserEvent.eventData(), 905 event_type: "VIDEO_SHARE_CLICKED", 906 event_value: auwUserEvent.entityId(), 907 }; 908 auwUserEvent.fetch(data); 909 }); 910 }, 911 912 sharedPlatform: function () { 913 document.addEventListener('click', async function (e) { 914 const shareEl = e.target.closest('[share-type], .sharingIconDv.xIcon'); 915 if (!shareEl) return; 916 let shareType = shareEl.getAttribute('share-type') || (shareEl.classList.contains('xIcon') ? 'share-menu' : 'unknown'); 917 if (shareType) { 918 shareType = shareType.toUpperCase(); 919 const data = { 920 userData: auwUserEvent.eventData(), 921 event_type: `VIDEO_SHARE_CLICKED_ON_${shareType}`, 922 event_value: auwUserEvent.entityId(), 923 }; 924 auwUserEvent.fetch(data); 925 } 926 }); 927 }, 928 929 widgetEvent: function () { 930 $(document).on('scroll', function () { 931 function inViewport(element) { 932 if (element) { 933 const rect = element.getBoundingClientRect(); 934 return ( 935 rect.top >= 0 && 936 rect.left >= 0 && 937 rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && 938 rect.right <= (window.innerWidth || document.documentElement.clientWidth) 939 ); 940 }; 941 return null; 942 }; 943 944 const box = document.querySelector(".moreArticles"); 945 const result = inViewport(box); 946 auwUserEvent.createCookie("widget_event", "false"); 947 948 if (result) { 949 let template = typeof _auw_page_detail !== "undefined" ? _auw_page_detail.template : null; 950 if (template == "story" || template == "feature-story" || template == "photo-gallery" || template == "wiki" || template == "live" || template == "blog") { 951 if (auwUserEvent.getCookie("widget_event") === "false") { 952 window.MyJSClient.webview_events_cdp("RECOMMENDATION_WIDGET_VIEW_EVENT", payload) 953 auwUserEvent.createCookie("widget_event", "true"); 954 }; 955 }; 956 }; 957 }); 958 }, 959 960 shabdKhoj: function () { 961 const page_type = this.urlFormatter().slug; 962 const client = this.urlFormatter()?.queryObject?.client_new; 963 964 if (page_type === "shabd-khoj") { 965 const introStartBtn = document.getElementById("introStartBtn"); 966 if (client === "au_revamp") { 967 const app_version = window?.MyJSClient?.getAndroidAppVersion(); 968 let value = parseInt(app_version?.split(".").pop()); 969 if (value > 32) { 970 window?.MyJSClient?.webview_events_cdp("GAME_START", this.appPayload()); 971 }; 972 }; 973 introStartBtn.addEventListener("click", function () { 974 // if (client === "au_revamp") window.MyJSClient.webview_events_cdp("GAME_START", this.appPayload()); 975 }); 976 977 const gameOverModal = document.getElementById("gameOverModal"); 978 979 const observer = new MutationObserver(() => { 980 if (gameOverModal.classList.contains("show")) { 981 const message = gameOverModal.querySelector("#modalMessage")?.textContent.trim(); 982 const yourScore = gameOverModal.querySelector("#modalYourScore")?.textContent.trim(); 983 const bestScore = gameOverModal.querySelector("#modalBestScore")?.textContent.trim(); 984 985 const temp = this.appPayload(); 986 if (client === "au_revamp") { 987 const app_version = window?.MyJSClient?.getAndroidAppVersion(); 988 let value = parseInt(app_version?.split(".").pop()); 989 if (value > 32) { 990 window?.MyJSClient?.webview_events_cdp("GAME_COMPLETE", temp); 991 temp["event_value"] = parseInt(yourScore); 992 window?.MyJSClient?.webview_events_cdp("GAME_SCORE", temp); 993 }; 994 }; 995 }; 996 }); 997 observer.observe(gameOverModal, { attributes: true, attributeFilter: ["class"] }); 998 }; 999 }, 1000 1001 wordMala: function () { 1002 const page_type = this.urlFormatter().slug;
1003 const client = this.urlFormatter()?.queryObject?.client_new; 1004 1005 if (page_type === "word-mala") { 1006 if (client === "au_revamp") { 1007 const app_version = window?.MyJSClient?.getAndroidAppVersion(); 1008 let value = parseInt(app_version?.split(".").pop()); 1009 if (value > 32) { 1010 window?.MyJSClient?.webview_events_cdp("GAME_START", this.appPayload()); 1011 }; 1012 }; 1013 1014 const modal = document.getElementById("modal-overlay"); 1015 1016 const observer = new MutationObserver(() => { 1017 const isOpen = getComputedStyle(modal).display !== "none"; 1018 if (isOpen) { 1019 const statGroups = document.getElementById("stat-groups").textContent.trim(); 1020 const lives = document.getElementById("stat-lives").textContent.trim(); 1021 const time = document.getElementById("stat-time").textContent.trim(); 1022 const attempts = document.getElementById("stat-attempts").textContent.trim(); 1023 1024 const temp = this.appPayload(); 1025 if (client === "au_revamp") { 1026 const app_version = window?.MyJSClient?.getAndroidAppVersion(); 1027 let value = parseInt(app_version?.split(".").pop()); 1028 if (value > 32) { 1029 window?.MyJSClient?.webview_events_cdp("GAME_COMPLETE", temp); 1030 }; 1031 }; 1032 // window.MyJSClient.webview_events_cdp("GAME_SCORE", temp); 1033 }; 1034 }); 1035 observer.observe(modal, { attributes: true, attributeFilter: ["class"] }); 1036 }; 1037 }, 1038 1039 chitraMala: function () { 1040 const page_type = this.urlFormatter().slug; 1041 const client = this.urlFormatter()?.queryObject?.client_new; 1042 1043 if (page_type === "chitra-mala") { 1044 if (client === "au_revamp") { 1045 const app_version = window?.MyJSClient?.getAndroidAppVersion(); 1046 let value = parseInt(app_version?.split(".").pop()); 1047 if (value > 32) { 1048 window?.MyJSClient?.webview_events_cdp("GAME_START", this.appPayload()); 1049 }; 1050 }; 1051 1052 const modal = document.getElementById("modal-overlay"); 1053 1054 const observer = new MutationObserver(() => { 1055 const isOpen = getComputedStyle(modal).display !== "none"; 1056 if (isOpen) { 1057 const statGroups = document.getElementById("stat-groups").textContent.trim(); 1058 const lives = document.getElementById("stat-lives").textContent.trim(); 1059 const time = document.getElementById("stat-time").textContent.trim(); 1060 const attempts = document.getElementById("stat-attempts").textContent.trim(); 1061 1062 const temp = this.appPayload(); 1063 if (client === "au_revamp") { 1064 const app_version = window?.MyJSClient?.getAndroidAppVersion(); 1065 let value = parseInt(app_version?.split(".").pop()); 1066 if (value > 32) { 1067 window?.MyJSClient?.webview_events_cdp("GAME_COMPLETE", temp); 1068 }; 1069 } 1070 // window.MyJSClient.webview_events_cdp("GAME_SCORE", temp); 1071 }; 1072 }); 1073 observer.observe(modal, { attributes: true, attributeFilter: ["class"] }); 1074 }; 1075 }, 1076 1077 selectPlan: function () { 1078 const template = auwUserEvent.screenName().split("_")[0]; 1079 if (template === "subscription") { 1080 function updateSelectedPlan() { 1081 const $selected = $('#planCardsForm input[name="plan"]:checked'); 1082 if (!$selected.length) return; 1083 const selected_plan = $selected.data(); 1084 sessionStorage.setItem("selectedPlan", JSON.stringify([selected_plan.price, selected_plan.planName, selected_plan.buyableId, selected_plan.currencyCode, false])); 1085 1086 if (auwUserEvent.clientCheck()) {
1087 let temp = auwUserEvent.appPayload(); 1088 temp["planId"] = selected_plan.buyableId; 1089 temp["plan"] = selected_plan.planName; 1090 temp["price"] = selected_plan.price; 1091 temp["currency"] = selected_plan.currencyCode; 1092 temp["isDefault"] = false; 1093 window?.MyJSClient?.webview_events_cdp("ITEM_SELECTED", temp); 1094 } else { 1095 const data = { 1096 userData: auwUserEvent.eventData(), 1097 event_type: "ITEM_SELECTED", 1098 event_value: JSON.parse(sessionStorage.getItem("selectedPlan")) || [] 1099 }; 1100 auwUserEvent.fetch(data); 1101 }; 1102 }; 1103 1104 // $(document).on('change', '#planCardsForm input[name="plan"]', function () { 1105 // updateSelectedPlan(); 1106 // }); 1107 1108 $(document).off('change.planSelection', '#planCardsForm input[name="plan"]') 1109 .on('change.planSelection', '#planCardsForm input[name="plan"]', updateSelectedPlan); 1110 }; 1111 }, 1112 1113 buyPlan: function () { 1114 const template = auwUserEvent.screenName().split("_")[0]; 1115 if (template === "subscription") { 1116 document.addEventListener("click", (event) => { 1117 const btn = event.target.closest(".au_cta_btn"); 1118 if (!btn) return; 1119 1120 if (btn.dataset.eventFired === "true") return; 1121 btn.dataset.eventFired = "true"; 1122 1123 const priceElement = btn.querySelector('.js-cta-price'); 1124 const buttonPriceText = priceElement ? priceElement.textContent.trim() : null; 1125 const buttonNumericPrice = buttonPriceText ? parseFloat(buttonPriceText.replace(/[^\d.]/g, '')) : 0; 1126 sessionStorage.setItem("value", buttonNumericPrice); 1127 1128 const $selected = $('#planCardsForm input[name="plan"]:checked'); 1129 if (!$selected.length) return; 1130 const selected_plan = $selected.data(); 1131 1132 if (auwUserEvent.clientCheck()) { 1133 let temp = auwUserEvent.appPayload(); 1134 temp["planId"] = selected_plan.buyableId; 1135 temp["plan"] = selected_plan.planName; 1136 temp["price"] = selected_plan.price; 1137 temp["currency"] = selected_plan.currencyCode; 1138 temp["coupon"] = sessionStorage.getItem("couponCode") || null; 1139 temp["value"] = buttonNumericPrice; 1140 temp["discountAmount"] = parseFloat(selected_plan.price) - buttonNumericPrice; 1141 window?.MyJSClient?.webview_events_cdp("ADD_TO_CART", temp); 1142 1143 // if (auwUserEvent.getCookie("_raidu")) { 1144 // let temp = auwUserEvent.appPayload(); 1145 // temp["planId"] = selected_plan.buyableId; 1146 // temp["plan"] = selected_plan.planName; 1147 // temp["price"] = selected_plan.price; 1148 // temp["currency"] = selected_plan.currencyCode; 1149 // temp["coupon"] = sessionStorage.getItem("couponCode") || null; 1150 // temp["value"] = buttonNumericPrice; 1151 // temp["discountAmount"] = parseFloat(selected_plan.price) - buttonNumericPrice; 1152 // window?.MyJSClient?.webview_events_cdp("BEGIN_CHECKOUT", temp); 1153 // } 1154 } else { 1155 const data = { 1156 userData: auwUserEvent.eventData(), 1157 event_type: "ADD_TO_CART", 1158 event_value: JSON.parse(sessionStorage.getItem("selectedPlan")) || [], 1159 coupon: sessionStorage.getItem("couponCode") || null, 1160 discountAmount: sessionStorage.getItem("discountedPrice") || null, 1161 value: buttonNumericPrice 1162 }; 1163 auwUserEvent.fetch(data); 1164 1165 // if (auwUserEvent.getCookie("_raidu")) { 1166 // const data = { 1167 // userData: auwUserEvent.eventData(), 1168 // event_type: "BEGIN_CHECKOUT", 1169 // event_value: JSON.parse(sessionStorage.getItem("selectedPlan")) || [], 1170 // coupon: sessionStorage.getItem("couponCode") || null, 1171 // discountAmount: sessionStorage.getItem("discountedPrice") || null, 1172 // value: buttonNumericPrice 1173 // }; 1174 // auwUserEvent.fetch(data); 1175 // }; 1176 }; 1177 }); 1178 }; 1179 }, 1180 1181 premiumWall: function () { 1182 (function () { 1183 function fire(name, detail) { 1184 window.dispatchEvent(new CustomEvent(name, { 1185 detail, 1186 bubbles: true 1187 })); 1188 } 1189 1190 function setup() { 1191 const wrapper = document.querySelector('.premium_wall_wrapper'); 1192 const visiblePaywall = document.querySelector('.premium-wall-article-subscription'); 1193 const button = document.querySelector('.premium-wall-article-subscription .login_button.login'); 1194 1195 if (!wrapper) return; 1196 1197 if (button && !button.dataset.bound) { 1198 button.dataset.bound = '1'; 1199 button.addEventListener('click', function (e) { 1200 fire('paywallClick', { source: 'button', target: e.currentTarget }); 1201 }); 1202 } 1203 1204 const target = visiblePaywall || wrapper; 1205 if (!target) return; 1206 1207 if ('IntersectionObserver' in window) { 1208 const io = new IntersectionObserver((entries, obs) => {
1209 entries.forEach(entry => { 1210 if (entry.isIntersecting) { 1211 fire('paywallVisible', { source: 'intersection', target: entry.target }); 1212 obs.unobserve(entry.target); 1213 } 1214 }); 1215 }, { threshold: 0.01 }); 1216 1217 io.observe(target); 1218 } else { 1219 const check = () => { 1220 const r = target.getBoundingClientRect(); 1221 if (r.top < window.innerHeight && r.bottom > 0) { 1222 fire('paywallVisible', { source: 'scroll', target }); 1223 window.removeEventListener('scroll', check); 1224 window.removeEventListener('resize', check); 1225 } 1226 }; 1227 window.addEventListener('scroll', check, { passive: true }); 1228 window.addEventListener('resize', check); 1229 check(); 1230 } 1231 } 1232 1233 if (document.readyState === 'loading') { 1234 document.addEventListener('DOMContentLoaded', setup); 1235 } else { 1236 setup(); 1237 }; 1238 1239 window.addEventListener('paywallVisible', e => { 1240 if (auwUserEvent.clientCheck()) { 1241 let temp = auwUserEvent.appPayload(); 1242 temp["isPremium"] = true; 1243 temp["isPayWalled"] = true; 1244 window?.MyJSClient?.webview_events_cdp("PAYWALL_VIEW", temp); 1245 } else { 1246 const data = { 1247 userData: auwUserEvent.eventData(), 1248 event_type: "PAYWALL_VIEW", 1249 event_value: auwUserEvent.entityId() 1250 }; 1251 data["isPremium"] = true; 1252 data["isPayWalled"] = true; 1253 auwUserEvent.fetch(data); 1254 }; 1255 }); 1256 1257 window.addEventListener('paywallClick', e => { 1258 if (auwUserEvent.clientCheck()) { 1259 let temp = auwUserEvent.appPayload(); 1260 temp["isPremium"] = true; 1261 temp["isPayWalled"] = true; 1262 temp["paywallCtaType"] = "subscribe"; 1263 window?.MyJSClient?.webview_events_cdp("PAYWALL_ClICK", temp); 1264 } else { 1265 const data = { 1266 userData: auwUserEvent.eventData(), 1267 event_type: "PAYWALL_ClICK", 1268 event_value: auwUserEvent.entityId() 1269 }; 1270 data["isPremium"] = true; 1271 data["isPayWalled"] = true; 1272 data["paywallCtaType"] = "subscribe"; 1273 auwUserEvent.fetch(data); 1274 }; 1275 }); 1276 })(); 1277 }, 1278 1279 planPageImpression: function () { 1280 (function () { 1281 const VIS_EVENT = 'planDetailsVisible'; 1282 1283 function fire(name, detail) { 1284 window.dispatchEvent(new CustomEvent(name, { detail, bubbles: true })); 1285 }; 1286 1287 function observeVisibility(el) { 1288 if (!el || el.dataset.visibleBound === '1') return; 1289 el.dataset.visibleBound = '1'; 1290 1291 if ('IntersectionObserver' in window) { 1292 const io = new IntersectionObserver((entries, obs) => { 1293 entries.forEach(entry => { 1294 if (entry.isIntersecting) { 1295 fire(VIS_EVENT, { source: 'intersection', element: entry.target }); 1296 obs.unobserve(entry.target); 1297 } 1298 }); 1299 }, { threshold: 0.1 }); 1300 1301 io.observe(el); 1302 } else { 1303 const check = () => { 1304 const r = el.getBoundingClientRect(); 1305 if (r.top < window.innerHeight && r.bottom > 0) { 1306 fire(VIS_EVENT, { source: 'scroll', element: el }); 1307 window.removeEventListener('scroll', check); 1308 window.removeEventListener('resize', check); 1309 } 1310 }; 1311 window.addEventListener('scroll', check, { passive: true }); 1312 window.addEventListener('resize', check); 1313 check(); 1314 }; 1315 }; 1316
1317 function init() { 1318 // FIX 1: Look for any valid plan container (Card, Form, OR Table) 1319 const target = document.querySelector('.plan_card') || 1320 document.querySelector('#planCardsForm') || 1321 document.querySelector('#plansTable'); 1322 1323 if (target) { 1324 observeVisibility(target); 1325 return true; // Returns true when target is found 1326 } 1327 return false; 1328 }; 1329 1330 function setup() { 1331 // FIX 2: Only run this heavy logic if we are actually on a subscription page 1332 const template = auwUserEvent.screenName().split("_")[0]; 1333 if (template !== "subscription") return; 1334 1335 // Try to initialize immediately if DOM is ready 1336 if (init()) return; 1337 1338 // FIX 3: Ensure document.body exists before attaching the MutationObserver 1339 if (document.body) { 1340 const mo = new MutationObserver(() => { 1341 // Disconnect observer automatically once the element is found and bound 1342 if (init()) { 1343 mo.disconnect(); 1344 } 1345 }); 1346 1347 mo.observe(document.body, { childList: true, subtree: true }); 1348 } 1349 } 1350 1351 // Ensure we wait for the DOM to prevent `document.body` being null 1352 if (document.readyState === 'loading') { 1353 document.addEventListener('DOMContentLoaded', setup); 1354 } else { 1355 setup(); 1356 }; 1357 1358 // Listen for the custom event and fire the analytics fetch 1359 window.addEventListener(VIS_EVENT, e => { 1360 const $select = $('#planCardsForm input[name="plan"]:checked'); 1361 if ($select.length > 0) { 1362 const defaultPlan = $select.data(); 1363 sessionStorage.setItem("selectedPlan", JSON.stringify([defaultPlan?.price, defaultPlan?.planName, defaultPlan?.buyableId, defaultPlan?.currencyCode, true])); 1364 if (auwUserEvent.clientCheck()) { 1365 let temp = auwUserEvent.appPayload(); 1366 temp["planId"] = defaultPlan?.buyableId; 1367 temp["plan"] = defaultPlan?.planName; 1368 temp["price"] = defaultPlan?.price; 1369 temp["currency"] = defaultPlan?.currencyCode; 1370 temp["isDefault"] = true; 1371 window?.MyJSClient?.webview_events_cdp("ITEM_SELECTED", temp); 1372 } else { 1373 const data = { 1374 userData: auwUserEvent.eventData(), 1375 event_type: "ITEM_SELECTED", 1376 event_value: [defaultPlan?.price, defaultPlan?.planName, defaultPlan?.buyableId, defaultPlan?.currencyCode, true] 1377 }; 1378 auwUserEvent.fetch(data); 1379 }; 1380 }; 1381 1382 if (auwUserEvent.clientCheck()) { 1383 let temp = auwUserEvent.appPayload(); 1384 window?.MyJSClient?.webview_events_cdp("VIEW_ITEM_LIST", temp); 1385 } else { 1386 const data = { 1387 userData: auwUserEvent.eventData(), 1388 event_type: "VIEW_ITEM_LIST", 1389 event_value: auwUserEvent.entityId() 1390 }; 1391 auwUserEvent.fetch(data); 1392 }; 1393 }); 1394 })(); 1395 }, 1396 1397 loginWall: function () { 1398 (function () { 1399 // FIX 2: Rename events to avoid triggering premiumWall's listeners 1400 const VIS_EVENT = 'loginWallVisible'; 1401 const CLICK_EVENT = 'loginWallClick'; 1402 1403 function fire(name, detail) { 1404 window.dispatchEvent(new CustomEvent(name, { detail, bubbles: true })); 1405 } 1406 1407 function bindClickDelegation() { 1408 if (!document.body || document.body.dataset.loginCl
1408ickBound === '1') return; 1409 document.body.dataset.loginClickBound = '1'; 1410 1411 document.body.addEventListener('click', function (e) { 1412 // FIX 1: Target the login button, explicitly EXCLUDING the subscribe button 1413 const btn = e.target.closest('.premium_wall_wrapper .login_button:not(.login)'); 1414 if (!btn) return; 1415 1416 fire(CLICK_EVENT, { 1417 source: 'button', 1418 text: btn.textContent.trim() 1419 }); 1420 }); 1421 } 1422 1423 function observeVisibleWall() { 1424 const wall = document.querySelector('.premium_wall_wrapper'); 1425 if (!wall) return false; 1426 1427 // Only target the login article, not the subscription one 1428 const visibleTarget = wall.querySelector('.premium-wall-article:not([style*="display: none"])'); 1429 if (!visibleTarget) return false; 1430 1431 if (visibleTarget.dataset.loginVisibleBound === '1') return true; 1432 1433 visibleTarget.dataset.loginVisibleBound = '1'; 1434 1435 const emit = (source) => fire(VIS_EVENT, { source, targetClass: visibleTarget.className }); 1436 1437 if ('IntersectionObserver' in window) { 1438 const io = new IntersectionObserver((entries, obs) => { 1439 entries.forEach(entry => { 1440 if (entry.isIntersecting) { 1441 emit('intersection'); 1442 obs.unobserve(entry.target); 1443 } 1444 }); 1445 }, { threshold: 0.01 }); 1446 1447 io.observe(visibleTarget); 1448 } else { 1449 const check = () => { 1450 const r = visibleTarget.getBoundingClientRect(); 1451 if (r.top < window.innerHeight && r.bottom > 0) { 1452 emit('scroll'); 1453 window.removeEventListener('scroll', check); 1454 window.removeEventListener('resize', check); 1455 } 1456 }; 1457 window.addEventListener('scroll', check, { passive: true }); 1458 window.addEventListener('resize', check); 1459 check(); 1460 } 1461 return true; 1462 } 1463 1464 function setup() { 1465 if (!document.body) return; 1466 bindClickDelegation(); 1467 1468 if (observeVisibleWall()) return; 1469 1470 const mo = new MutationObserver(() => { 1471 if (observeVisibleWall()) { 1472 mo.disconnect(); 1473 } 1474 }); 1475 mo.observe(document.body, { childList: true, subtree: true }); 1476 } 1477 1478 if (document.readyState === 'loading') { 1479 document.addEventListener('DOMContentLoaded', setup); 1480 } else { 1481 setup(); 1482 } 1483 1484 // Listen for the unique LOGIN events 1485 window.addEventListener(VIS_EVENT, e => { 1486 if (auwUserEvent.clientCheck()) { 1487 let temp = auwUserEvent.appPayload(); 1488 temp["isPremium"] = true; 1489 temp["isLoginWalled"] = true; 1490 window?.MyJSClient?.webview_events_cdp("LOGIN_WALL_VIEW", temp); 1491 } else { 1492 const data = { 1493 userData: auwUserEvent.eventData(), 1494 event_type: "LOGIN_WALL_VIEW", 1495 event_value: auwUserEvent.entityId() 1496 }; 1497 data["isPremium"] = true; 1498 data["isLoginWalled"] = true; 1499 auwUserEvent.fetch(data); 1500 }; 1501 }); 1502 1503 window.addEventListener(CLICK_EVENT, e => { 1504 if (auwUserEvent.clientCheck()) { 1505 let temp = auwUserEvent.appPayload(); 1506 temp["isPremium"] = true; 1507 temp["isLoginWalled"] = true; 1508 temp["paywallCtaType"] = "login"; 1509 window?.MyJSClient?.webview_events_cdp("LOGIN_WALL_CLICK", temp); 1510 } else { 1511 const data = { 1512 userData: auwUserEvent.eventData(), 1513 event_type: "LOGIN_WALL_CLICK", 1514 event_value: auwUserEvent.entityId() 1515 }; 1516 data["isPremium"] = true; 1517 data["isLoginWalled"] = true; 1518 data["paywallCtaType"] = "login"; 1519 auwUserEvent.fetch(data); 1520 }; 1521 }); 1522 })(); 1523 }, 1524 1525 couponEvent: function () { 1526 const template_type = auwUserEvent.screenName().split("_")[0]; 1527 if (template_type === "subscription") { 1528 1529 let couponInputTimer; 1530 1531 // 1. INPUT EVENT: Unbind specific 'input.couponTrack' namespace, then rebind 1532 $(document) 1533 .off('input.couponTrack') 1534 .on('input.couponTrack', '#coupon-code, .js-coupon-input', function (e) { 1535 clearTimeout(couponInputTimer); 1536 1537 couponInputTimer = setTimeout(() => { 1538 const couponValue = e.target.value.trim(); 1539 if (!couponValue) return; 1540 1541 sessionStorage.setItem("couponCode", couponValue); 1542 const selectedPlan = JSON.parse(sessionStorage.getItem("selectedPlan")) || []; 1543 1544 if (auwUserEvent.clientCheck()) {
1545 let temp = auwUserEvent.appPayload(); 1546 temp["coupon"] = couponValue; 1547 temp["planId"] = selectedPlan[2] || null; 1548 temp["plan"] = selectedPlan[1] || null; 1549 temp["price"] = selectedPlan[0] || null; 1550 window?.MyJSClient?.webview_events_cdp("COUPON_CODE_ENTERED", temp); 1551 } else { 1552 const data = { 1553 userData: auwUserEvent.eventData(), 1554 event_type: "COUPON_CODE_ENTERED", 1555 event_value: selectedPlan, 1556 coupon: couponValue 1557 }; 1558 auwUserEvent.fetch(data); 1559 }; 1560 }, 500); 1561 }); 1562 1563 // 2. SUCCESS EVENT: Unbind before binding 1564 $(document) 1565 .off('newcta:coupon:applied') 1566 .on('newcta:coupon:applied', function (e, discountedPrice) { 1567 let selectedPlan = JSON.parse(sessionStorage.getItem("selectedPlan")) || []; 1568 let couponValue = sessionStorage.getItem("couponCode"); 1569 1570 if (auwUserEvent.clientCheck()) { 1571 let temp = auwUserEvent.appPayload(); 1572 temp["coupon"] = couponValue; 1573 temp["planId"] = selectedPlan[2] || null; 1574 temp["plan"] = selectedPlan[1] || null; 1575 temp["price"] = selectedPlan[0] || null; 1576 window?.MyJSClient?.webview_events_cdp("COUPON_APPLY_SUCCESSFUL", temp); 1577 } else { 1578 const data = { 1579 userData: auwUserEvent.eventData(), 1580 event_type: "COUPON_APPLY_SUCCESSFUL", 1581 event_value: selectedPlan, 1582 coupon: couponValue 1583 }; 1584 auwUserEvent.fetch(data); 1585 }; 1586 }); 1587 1588 // 3. FAIL EVENT: Unbind before binding 1589 $(document) 1590 .off('newcta:coupon:fail') 1591 .on('newcta:coupon:fail', function (e, errorMessage) { 1592 let selectedPlan = JSON.parse(sessionStorage.getItem("selectedPlan")) || []; 1593 let couponValue = sessionStorage.getItem("couponCode"); 1594 1595 if (couponValue !== null) { 1596 sessionStorage.removeItem("couponCode"); 1597 }; 1598 1599 if (auwUserEvent.clientCheck()) { 1600 let temp = auwUserEvent.appPayload(); 1601 temp["coupon"] = couponValue; 1602 temp["planId"] = selectedPlan[2] || null; 1603 temp["plan"] = selectedPlan[1] || null; 1604 temp["price"] = selectedPlan[0] || null; 1605 window?.MyJSClient?.webview_events_cdp("COUPON_APPLY_FAILED", temp); 1606 } else { 1607 const data = { 1608 userData: auwUserEvent.eventData(), 1609 event_type: "COUPON_APPLY_FAILED", 1610 event_value: selectedPlan, 1611 coupon: couponValue 1612 }; 1613 auwUserEvent.fetch(data); 1614 } 1615 }); 1616 } 1617 }, 1618 1619 clientCheck: function () { 1620 const client = this.urlFormatter()?.queryObject?.client_new; 1621 if (client === "au_revamp") { 1622 const app_version = window?.MyJSClient?.getAndroidAppVersion(); 1623 let value = parseInt(app_version?.split(".").pop()); 1624 if (value > 32) { 1625 return true; 1626 } else { 1627 return false; 1628 }; 1629 } else { 1630 return false; 1631 }; 1632 } 1633}; 1634 1635document.addEventListener("visibilitychange", (event) => { 1636 if (document.visibilityState == "visible") { 1637 let current_time = new Date().getTime(); 1638 sessionStorage.setItem("auw_initialTime", current_time); 1639 sessionStorage.setItem("readTime", 0); 1640 } else { 1641 let t1 = sessionStorage.getItem("auw_initialTime"); 1642 t1 = parseInt(t1); 1643 1644 let t2 = new Date().getTime(); 1645 t2 = parseInt(t2); 1646 1647 let time = Math.floor((t2 - t1) / 1000); 1648 const data = { 1649 userData: auwUserEvent.eventData(), 1650 event_type: "readtime", 1651 event_value: parseInt(time), 1652 page_height: $(document).height(), 1653 scroll_height: $(window).scrollTop(), 1654 scroll_depth: parseInt(sessionStorage.getItem("scroll_depth")) 1655 }; 1656 auwUserEvent.fetch(data); 1657 }; 1658}); 1659 1660// ! TO TRACK USER EVENT WHEN WINDOW LOAD 1661 1662try { 1663 auwUserEvent.originTime(); 1664 auwUserEvent.guestId(); 1665 auwUserEvent._recuih(); 1666 auwUserEvent.setSessionId(); 1667 auwUserEvent.setAcqSource(); 1668 auwUserEvent.loadTime(); 1669 auwUserEvent.setDailyStoryViewCount(); 1670 auwUserEvent.datesAreOnSameDay(); 1671 // auwUserEvent.eventBookmark(); 1672 // auwUserEvent.eventShare(); 1673 auwUserEvent.eventScroll(); 1674 auwUserEvent.qualityReadTime(); 1675 auwUserEvent.storyLikeDisLike(); 1676 auwUserEvent.authorFollowUnfollow();
1677 auwUserEvent.sharedClicked(); 1678 auwUserEvent.sharedPlatform(); 1679 // auwUserEvent.widgetEvent(); 1680 auwUserEvent.shabdKhoj(); 1681 auwUserEvent.wordMala(); 1682 auwUserEvent.chitraMala(); 1683 auwUserEvent.selectPlan(); 1684 auwUserEvent.buyPlan(); 1685 auwUserEvent.premiumWall(); 1686 auwUserEvent.loginWall(); 1687 auwUserEvent.planPageImpression(); 1688 auwUserEvent.couponEvent(); 1689} catch (error) { console.log(error); }; 1690 1691 1692window.addEventListener('message', (event) => { 1693 const { eventType, currentTime, story_id } = event.data; 1694 if (eventType) { 1695 const event = eventType ? eventType.toUpperCase() : null; 1696 const client = auwUserEvent.urlFormatter()?.queryObject?.client_new; 1697 if (client === "au_revamp") { 1698 const app_version = window?.MyJSClient?.getAndroidAppVersion(); 1699 let value = parseInt(app_version?.split(".").pop()); 1700 if (value > 32) { 1701 const app_payload = auwUserEvent.appPayload(); 1702 app_payload["videoProvider"] = "youtube"; 1703 app_payload["videoDuration"] = auwUserEvent?.videoDetails()["videoDuration"]; 1704 app_payload["videoCurrentDuration"] = currentTime; 1705 window?.MyJSClient?.webview_events_cdp(`${event}`, app_payload); 1706 } else { 1707 const data = { 1708 userData: auwUserEvent.eventData(), 1709 event_type: event, 1710 event_value: currentTime || 0, 1711 videoDuration: auwUserEvent.videoDetails(), 1712 }; 1713 let template = typeof _auw_page_detail !== "undefined" ? _auw_page_detail?.template : null; 1714 data["videoProvider"] = (template === "videoshots") ? "auw_video" : (typeof leadVideoJson !== "undefined") ? leadVideoJson?.video_type : null, 1715 data["userData"]["entity_id"] = story_id || auwUserEvent.entityId(); 1716 auwUserEvent.fetch(data); 1717 }; 1718 } else { 1719 const data = { 1720 userData: auwUserEvent.eventData(), 1721 event_type: event, 1722 event_value: currentTime || 0, 1723 videoDuration: auwUserEvent.videoDetails(), 1724 }; 1725 let template = typeof _auw_page_detail !== "undefined" ? _auw_page_detail?.template : null; 1726 data["videoProvider"] = (template === "videoshots") ? "auw_video" : (typeof leadVideoJson !== "undefined") ? leadVideoJson?.video_type : null; 1727 data["userData"]["entity_id"] = story_id || auwUserEvent.entityId(); 1728 auwUserEvent.fetch(data); 1729 }; 1730 }; 1731});
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.