1// ================================================================ 2// CYBX TRACKING COOKIE HANDLER 3// Runs immediately on every page load (no jQuery dependency). 4// Reads URL params via URLSearchParams, stores into 30-day cookies. 5// ================================================================ 6(function () { 7 var params = new URLSearchParams(window.location.search); 8 9 // âââ¬Ã¢â⬠Helpers âââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢â⬠10 function setCookie(name, value) { 11 if (!value) return; 12 var expires = new Date(Date.now() + 30 * 864e5).toUTCString(); // 30 days 13 document.cookie = name + '=' + encodeURIComponent(value) 14 + '; expires=' + expires 15 + '; path=/' 16 + '; domain=.cybx.in' 17 + '; SameSite=Lax'; 18 } 19 20 function getCookie(name) { 21 var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); 22 return match ? decodeURIComponent(match[2]) : ''; 23 } 24 25 // âââ¬Ã¢â⬠Visitor ID (generate once, never overwrite) âââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢â⬠26 if (!getCookie('cybx_visitor_id')) { 27 var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { 28 var r = Math.random() * 16 | 0; 29 return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); 30 }); 31 setCookie('cybx_visitor_id', uuid); 32 } 33 34 // âââ¬Ã¢â⬠Click IDs âââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢â⬠35 var fbclid = params.get('fbclid'); 36 var gclid = params.get('gclid'); 37 var amzn_cid = params.get('amzn_cid'); 38 var moloco_tid = params.get('moloco_tid'); 39 40 if (fbclid) setCookie('cybx_fbclid', fbclid); 41 if (gclid) setCookie('cybx_gclid', gclid); 42 if (amzn_cid) setCookie('cybx_amzn_cid', amzn_cid); 43 if (moloco_tid) setCookie('cybx_moloco_tid', moloco_tid); 44 45 // âââ¬Ã¢â⬠fbc: computed from fbclid, first-touch only âââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢â⬠46 if (fbclid && !getCookie('cybx_fbc')) { 47 setCookie('cybx_fbc', 'fb.1.' + Date.now() + '.' + fbclid); 48 } 49 50 // âââ¬Ã¢â⬠fbp: copy from Meta Pixel cookie if present âââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢â⬠51 var fbp = getCookie('_fbp'); 52 if (fbp && !getCookie('cybx_fbp')) { 53 setCookie('cybx_fbp', fbp); 54 } 55 56 // âââ¬Ã¢â⬠UTM params âââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢â⬠57 ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term'].forEach(function (key) { 58 var val = params.get(key); 59 if (val) setCookie('cybx_' + key, val); 60 }); 61 62 // âââ¬Ã¢â⬠AppsFlyer sub params âââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢â⬠63 for (var i = 1; i <= 5; i++) { 64 var afVal = params.get('af_sub' + i); 65 if (afVal) setCookie('cybx_af_sub' + i, afVal); 66 } 67 68 // âââ¬Ã¢â⬠cybx-ref / Code âââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢â⬠69 var ref = params.get('cybx-ref') || params.get('Code'); 70 if (ref) setCookie('cybx_ref', ref); 71 72 // âââ¬Ã¢â⬠Landing URL + Referrer (first-touch only) âââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢ââ¬Ã¢â⬠73 if (!getCookie('cybx_landing_url')) { 74 setCookie('cybx_landing_url', window.location.href); 75 } 76 if (!getCookie('cybx_referrer') && document.referrer) { 77 setCookie('cybx_referrer', document.referrer); 78 } 79 80})(); 81// ================================================================ 82// END CYBX TRACKING COOKIE HANDLER 83// ================================================================ 84 85jQuery(document).ready(function ($) { 86 /////AOS 87 window.addEventListener('load', function () { 88 AOS.init({ 89 duration: 1200, 90 disable: function () { 91 var maxWidth = 800; 92 return window.innerWidth < maxWidth; 93 }, 94 }); 95 }); 96 /////AOS 97 98 // AppsFlyer: Plans page view 99 var path = (window.location.pathname || "").toLowerCase(); 100 if (path.indexOf("/plans") !== -1 || path.indexOf("/promo-plans") !== -1) { 101 AF('pba', 'event', { 102 eventType: 'EVENT', 103 eventName: 'plans_PageView', 104 eventValue: { 105 pageURL: window.location.href 106 } 107 }); 108 } 109 110 // Global function 111 window.redirectToTargetOrFallback = function (fallbackPath = '/plans') { 112 const params = new URLSearchParams(window.location.search); 113 const redirectTo = params.get("redirect_to"); 114 if (redirectTo) { 115 const decoded = decodeURIComponent(redirectTo); 116 117 // Check if the URL is relative (starts with "/" but not "//" which points to external protocols) 118 if (decoded.startsWith('/') && !decoded.startsWith('//')) { 119 window.location.href = decoded; 120 } else { 121 // Alternatively, verify the parsed URL origin matches the current site origin
122 try { 123 const parsedUrl = new URL(decoded, window.location.origin); 124 if (parsedUrl.origin === window.location.origin) { 125 window.location.href = decoded; 126 return; 127 } 128 } catch (e) { 129 // Invalid URL format 130 } 131 132 // Fall back to plans page if target is external/invalid 133 window.location.href = fallbackPath; 134 } 135 } else { 136 window.location.href = fallbackPath; 137 } 138 }; 139 140 var btn = $("#goTop"); 141 142 $(window).scroll(function () { 143 if ($(window).scrollTop() > 300) { 144 btn.addClass("show"); 145 } else { 146 btn.removeClass("show"); 147 } 148 }); 149 150 btn.on("click", function (e) { 151 e.preventDefault(); 152 $("html, body").animate({ scrollTop: 0 }, "300"); 153 }); 154 155 $('#userHeader .user-visit-home').on('click', function () { 156 window.location.href = '/'; 157 }) 158 159 /* Logout on logout button click on dashboard page */ 160 $('#userHeader .user-logout').on('click', function () { 161 $.ajax({ 162 url: ajax_object.ajax_url, 163 type: 'POST', 164 data: { action: 'user_logout' }, 165 success: function (response) { 166 167 // Clear the customer user ID from Appsflyer 168 AF('pba', 'setCustomerUserId', null); 169 170 window.location.href = '/login'; 171 }, 172 error: function (xhr, status, error) { 173 // Handle AJAX error 174 alert('An error occurred during the logout process.'); 175 } 176 }); 177 }) 178 179 $('.closePop').on('click', function () { 180 $('.error-msg').text(''); 181 $('#profile-edit')[0].reset(); 182 }) 183 184 /* Profile image preview on choose image */ 185 $('#profileImage').on('change', function () { 186 const file = this.files[0]; 187 const allowedExtensions = /(\.jpg|\.jpeg|\.png)$/i; 188 const maxSize = 5 * 1024 * 1024; // 5 MB in bytes 189 const currImg = $('#previewImg').attr('src'); 190 191 $('.closePop').on('click', function () { 192 $('#previewImg').attr('src', currImg); 193 $('#imgErr').text(''); 194 $('.error-msg').text(''); 195 $('#profile-edit')[0].reset(); 196 }) 197 198 if (file) { 199 const reader = new FileReader(); 200 reader.onload = function (e) { 201 $('#previewImg').attr('src', e.target.result); 202 $('#previewImg').show(); 203 }; 204 reader.readAsDataURL(file); 205 if (allowedExtensions.exec(file.name)) { 206 $('#imgErr').text(''); 207 } else { 208 // $('#previewImg').hide(); 209 $('#imgErr').text('Only JPG, JPEG, and PNG formats are allowed.'); 210 } 211 212 if (allowedExtensions.exec(file.name)) { 213 if (file.size > maxSize) { 214 $('#imgErr').text('Image size should not exceed 5 MB.'); 215 // $('#previewImg').hide(); // Hide preview image if file size exceeds 5 MB 216 return; 217 } 218 } 219 220 } else { 221 $('#previewImg').hide(); 222 } 223 }); 224 225 226 /* Update profile details on Save button click */ 227 $("#submitForm").on("click", function () { 228 var error = false; 229 const fname = $("#fname").val(); 230 const lname = $("#lname").val(); 231 const email = $("#email").val(); 232 const addr1 = $("#addr1").val(); 233 const addr2 = $("#addr2").val(); 234 const pincode = $("#pincode").val(); 235 236 const state_code = $("#state_code").val(); 237 const city_code = $("#city_code").val(); 238 //const date_of_birth = $("#date_of_birth").val(); 239 240 241 const file = $('#profileImage')[0].files[0]; 242 const allowedExtensions = /(\.jpg|\.jpeg|\.png)$/i; 243 244 // const nameRegEx = new RegExp("^[a-zA-Z '\s-]+$"); 245 const nameRegEx = new RegExp("^[a-zA-Z \\s-]+$"); 246 const emailRegEx = new RegExp(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/); 247 // var addrReg = new RegExp(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi); 248 var addrReg = new RegExp(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>|[\(\)]/gi); 249 250 if (fname == '') { 251 $("#fnameErr").text("Please enter first name") 252 error = true; 253 } else if (!nameRegEx.test(fname) || fname.length > 30) { 254 $('#fnameErr').text('Please enter valid first name'); 255 error = true; 256 } else { 257 $('#fnameErr').text(""); 258 } 259 260 if (lname != '') { 261 if (!nameRegEx.test(lname) || lname.length > 30) { 262 $('#lnameErr').text('Please enter valid last name'); 263 error = true; 264 } else { 265 $('#lnameErr').text(""); 266 } 267 } 268 269 /*const today = new Date(); // Get the current date 270 const selectedDate = new Date($('#date_of_birth').val()); // Get the selected date 271 272 if ($('#date_of_birth').val() === '') { 273 $('#date_of_birth_Err').text('Please select your date of birth.'); 274 error = true; 275 } else if (selectedDate > today) { 276 $('#date_of_birth_Err').text('Date of birth cannot be a future date.'); 277 error = true; 278 } else { 279 280 // Calculate the difference in years 281 let age = today.getFullYear() - selectedDate.getFullYear(); 282 const monthDifference = today.getMonth() - selectedDate.getMonth(); 283 const dayDifference = today.getDate() - selectedDate.getDate(); 284 285 // Adjust age if the current date is before the user's birth date this year 286 if (monthDifference < 0 || (monthDifference === 0 && dayDifference < 0)) { 287 age--; 288 } 289 290 if (age < 18) { 291 $('#date_of_birth_Err').text('You must be at least 18 years old.'); 292 error = true; 293 } else { 294 $('#date_of_birth_Err').text(''); 295 } 296 }*/ 297 298 299 if (email == "") { 300 $('#emailErr').text('Please enter your email'); 301 error = true; 302 } 303 else if (!emailRegEx.test(email) || email.length > 50) { 304 $('#emailErr').text('Please enter valid email'); 305 error = true; 306 } else { 307 $('#emailErr').text(''); 308 } 309 310 if (addr1 != '' || addr1 != null) { 311 if (addrReg.test(addr1)) { 312 $('#addr1Err').text('Please enter valid address without parentheses or script tags'); 313 error = true; 314 } else if (addr1.length > 244) { 315 $('#addr1Err').text('The address entered exceeds the 245-character limit'); 316 error = true; 317 } else { 318 $('#addr1Err').text(''); 319 } 320 } 321 322 if (addr2 != '' || addr2 != null) { 323 if (addrReg.test(addr2)) { 324 $('#addr2Err').text('Please enter valid address without parentheses or script tags'); 325 error = true; 326 } else if (addr2.length > 244) { 327 $('#addr1Err').text('The address entered exceeds the 245-character limit'); 328 error = true; 329 } else { 330 $('#addr2Err').text(''); 331 } 332 } 333 334 335 if (pincode == '') { 336 $("#pincodeErr").text("Please enter your pincode") 337 error = true; 338 } else if (pincode.length > 0 && pincode.length != 6) { 339 $('#pincodeErr').text('Pincode must be exactly 6 digits long.'); 340 error = true; 341 } else { 342 $('#pincodeErr').text(""); 343 } 344 345 if (file && !allowedExtensions.exec(file.name)) { 346 $('#imgErr').text('Only JPG, JPEG, and PNG formats are allowed.'); 347 error = true; 348 } else if (file) { 349 $('#imgErr').text(''); 350 } 351 352 353 if (error == false) { 354 const formData = new FormData(); 355 formData.append('action', 'update_profile'); 356 formData.append('fname', fname); 357 formData.append('lname', lname); 358 formData.append('email', email); 359 formData.append('addr1', addr1); 360 formData.append('addr2', addr2); 361 formData.append('pincode', pincode); 362 formData.append('state_code', state_code); 363 formData.append('city_code', city_code); 364 //formData.append('date_of_birth', date_of_birth); 365 366 const imgFile = $('#profileImage')[0].files[0]; 367 if (imgFile) { 368 formData.append('profileImage', imgFile); 369 } 370 371 $.ajax({
372 url: ajax_object.ajax_url, 373 type: 'POST', 374 data: formData, 375 contentType: false, 376 processData: false, 377 success: function (response) { 378 var data = JSON.parse(response); 379 if (data.imageRes) { 380 if (data.imageRes.status == 'success' && data.profileRes.status == 'success') { 381 $("#errSection").text('Profile details updated successfully!'); 382 $("#profile-result").addClass('profile-success'); 383 setTimeout(function () { 384 location.reload(); 385 }, 500); 386 } else if (data.imageRes.status == 'failed') { 387 $('#imgErr').text(data.imageRes.message); 388 } else if (data.profileRes.status == 'failed') { 389 $("#errSection").text(data.profileRes.message); 390 $("#profile-result").addClass('profile-fail'); 391 } else { 392 $("#errSection").text('Something went wrong! Try again') 393 $("#profile-result").addClass('profile-fail'); 394 } 395 } else { 396 if (data.profileRes.status == 'success') { 397 $("#errSection").text('Profile details updated successfully!'); 398 $("#profile-result").addClass('profile-success'); 399 setTimeout(function () { 400 location.reload(); 401 }, 500); 402 } else if (data.profileRes.status == 'failed') { 403 $("#errSection").text(data.profileRes.message); 404 $("#profile-result").addClass('profile-fail'); 405 } else { 406 $("#errSection").text('Something went wrong! Try again') 407 $("#profile-result").addClass('profile-fail'); 408 } 409 } 410 411 // if(data.status == 'success'){ 412 // $("#errSection").text(data.message) 413 // }else{ 414 // $("#errSection").text('Something went wrong! Try again') 415 // } 416 }, 417 error: function (xhr, status, error) { 418 console.error('Error:', error); 419 } 420 }); 421 } 422 423 }) 424 425 /******* Script starts for Register Page *******/ 426 function validateMobile() { 427 duration = 0; 428 var error = false; 429 430 // Check if all elements exist before proceeding 431 if ($('#fname').length && $('#lname').length && $('#email').length) { 432 const nameRegEx = new RegExp("^[a-zA-Z \\s-]+$"); 433 const emailRegEx = new RegExp(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/); 434 var fname = $('#fname').val(); 435 var lname = $('#lname').val(); 436 var email = $('#email').val(); 437 438 if (fname == "") { 439 $("#fnameErr").text("Please enter first name"); 440 error = true; 441 } else if (!nameRegEx.test(fname) || fname.length > 30) { 442 $('#fnameErr').text('Please enter valid first name'); 443 error = true; 444 } else { 445 $('#fnameErr').text(""); 446 } 447 448 if ((lname != '') && (!nameRegEx.test(lname) || lname.length > 30)) { 449 $('#lnameErr').text('Please enter valid last name'); 450 error = true; 451 } else { 452 $('#lnameErr').text(""); 453 } 454 455 if (email == "") { 456 $('#emailErr').text('Please enter your email'); 457 error = true; 458 } 459 else if (!emailRegEx.test(email) || email.length > 50) { 460 $('#emailErr').text('Please enter valid email'); 461 error = true; 462 } else { 463 $('#emailErr').text(''); 464 } 465 } 466 467 var phoneNumber = $('#phone-number').val(); 468 var mobRegEx = new RegExp("[6-9]{1}[0-9]{9}"); 469 if (phoneNumber == "") { 470 $('#mobileErr').text('Please enter your mobile number'); 471 $('#mobileErr').addClass('error-msg'); 472 error = true; 473 } 474 else if (!mobRegEx.test(phoneNumber)) { 475 $('#mobileErr').text('Please enter valid mobile number'); 476 $('#mobileErr').addClass('error-msg'); 477 error = true; 478 } else { 479 $('#mobileErr').text(''); 480 $('#mobileErr').removeClass('error-msg'); 481 } 482 483 // If any error exists, stop execution 484 if (error) return; 485 486 // Get reCAPTCHA token and proceed 487 grecaptcha.ready(function () { 488 grecaptcha.execute(GRECAPTCHA_KEY, { action: 'register_send_otp' }).then(function (token) { 489 // Step 1: Validate Mobile Number 490 $.ajax({
491 url: ajax_object.ajax_url, 492 type: 'POST', 493 data: { 494 action: 'validate_mobile', 495 phone: phoneNumber 496 }, 497 success: function (response) { 498 try { 499 var data = JSON.parse(response); 500 if (data.success == true) { 501 // Mobile is valid, proceed to generate OTP 502 generateOtp(phoneNumber, token); 503 } else { 504 $('#mobileErr').text(data.message); 505 $('#mobileErr').addClass('error-msg'); 506 } 507 } catch (e) { 508 console.error("Error parsing JSON:", e, "Response:", response); 509 $('#mobileErr').text("Error validating mobile number. Please try again later."); 510 } 511 }, 512 error: function () { 513 $('#mobileErr').text("Error connecting to server. Please try again."); 514 } 515 }); 516 }); 517 }); 518 } 519 520 // Separate function to generate OTP 521 function generateOtp(phoneNumber, recaptchaToken) { 522 $.ajax({ 523 url: ajax_object.ajax_url, 524 type: 'POST', 525 data: { 526 action: 'generate_otp', 527 phone: phoneNumber, 528 recaptcha_token: recaptchaToken 529 }, 530 success: function (response) { 531 try { 532 var data = JSON.parse(response); 533 534 if (data.success == true) { 535 showOtpTimer(); 536 $('#verification-form').show(); 537 $('#otp-status').html('A 6 digit code has been sent <br>to +91 ' + phoneNumber); 538 $('#otp-form').hide(); 539 $('#mobileErr, #otpErr').text(''); 540 $('#mobileErr').text('A 6 digit OTP will be sent via SMS to verify your mobile number'); 541 } else { 542 console.error("Error:", response); 543 $('#mobileErr, #otpErr').text("OTP limit reached. Try again later."); 544 $('#mobileErr').addClass('error-msg'); 545 } 546 } catch (e) { 547 console.error("Error parsing JSON:", e, "Response:", response); 548 $('#mobileErr').text("Error processing OTP request. Please try again later."); 549 } 550 } 551 }); 552 } 553 554 $('#generate-otp-btn').click(function () { 555 validateMobile(); 556 }); 557 558 $('.rf #phone-number, .rf #fname, .rf #lname, .rf #email').on('keydown', function (event) { 559 if (event.key === "Enter" || event.keyCode === 13) { 560 event.preventDefault(); 561 validateMobile(); 562 } 563 }); 564 565 /* OTP timer code starts */ 566 var duration = 0 567 function showOtpTimer() { 568 var interval; 569 clearInterval(interval); 570 duration = 60; // 1 minute 571 var timerDisplay = $("#timerDisplay"); 572 timerDisplay.show(); 573 interval = setInterval(function () { 574 var minutes = Math.floor(duration / 60); 575 var seconds = duration % 60; 576 577 var formattedMinutes = String(minutes).padStart(2, '0'); 578 var formattedSeconds = String(seconds).padStart(2, '0'); 579 580 timerDisplay.html("Time Remaining: <b>" + formattedMinutes + ":" + formattedSeconds + "</b>"); 581 582 duration--; 583 584 if (duration < 0) { 585 clearInterval(interval); 586 $("#timerDisplay").html("Didn't recieve the code? <a class='resend-link' id='resend-otp'>Resend</a>") 587 } 588 }, 1000); 589 } 590 /* OTP timer code ends */ 591 592 $('#rg-back').on('click', function () { 593 $('#verification-form, .reg-suc').hide(); 594 $('#otp-form').show(); 595 $('#otp1').val(''); 596 $('#otp2').val(''); 597 $('#otp3').val(''); 598 $('#otp4').val(''); 599 $('#otp5').val(''); 600 $('#otp6').val(''); 601 $('#otpErr').text(''); 602 }); 603 604 $(".rf #otp6").on("keydown", function (e) { 605 if (event.key === "Enter" || event.keyCode === 13) { 606 event.preventDefault(); 607 registerUser(); 608 } 609 }); 610 611 $('.rf #verify-otp-btn').click(function () { 612 registerUser(); 613 }); 614 615 function registerUser() { 616 var error = false; 617 618 var otpCode = ""; 619 $(".otp-input-box").each(function () { 620 otpCode += $(this).val(); 621 }); 622 623 var phoneNumber = $('#phone-number').val(); 624 var fname = $('#fname').val(); 625 var lname = $('#lname').val(); 626 // Read email only if the field exists in the DOM 627 var email = $('#email').length ? $('#email').val() : ''; 628 629 // Email is optional if field has been removed from the form 630 if (fname === "" || phoneNumber === "") { 631 $('#otpErr').text('Cannot proceed! Enter user details in previous step.'); 632 error = true; 633 } else if (otpCode === "") { 634 $('#otpErr').text('Please enter OTP'); 635 error = true; 636 } else { 637 $('#otpErr').text(''); 638 } 639 640 if (!error) { 641 // query parameters will be shared to client-events API 642 let queryParams = Object.fromEntries(new URLSearchParams(window.location.search)); 643 644 // Optional: decode redirect_to if exists 645 if (queryParams.redirect_to) { 646 let decoded = decodeURIComponent(decodeURIComponent(queryParams.redirect_to)); 647 queryParams = decoded.split("?")[1] || decoded; 648 } 649 650 $.ajax({
651 url: ajax_object.ajax_url, 652 type: 'POST', 653 data: (function () { 654 // Build AJAX payload as a plain object ââ¬â avoids jQuery $.param TypeError 655 var payload = { 656 action: 'register_user', 657 phone: phoneNumber, 658 otp: otpCode, 659 fname: fname, 660 lname: lname, 661 // Ensure query_params is always a string, never an object/undefined 662 query_params: (typeof queryParams === 'string') 663 ? queryParams 664 : JSON.stringify(queryParams || {}) 665 }; 666 // Only add email if it was actually collected from the form 667 // if (email) { 668 // payload.email = email; 669 // } 670 return payload; 671 })(), 672 success: function (response) { 673 try { 674 var response = JSON.parse(response); 675 676 if (response.success == true) { 677 $('.reg-suc').show(); 678 $('#timerDisplay').remove(); 679 680 // Push OTP verified event to dataLayer 681 682 window.dataLayer = window.dataLayer || []; 683 684 window.dataLayer.push({ 685 686 'event': 'otp_verified' 687 688 }); 689 690 // Tell Appsflyer the registered person's contact number 691 AF('pba', 'setCustomerUserId', phoneNumber); 692 693 // ===== AppsFlyer registration event ===== 694 AF('pba', 'event', { 695 eventType: 'EVENT', 696 eventName: 'registration_success', 697 eventValue: { 698 firstName: fname, 699 lastName: lname, 700 email: email, 701 phone: phoneNumber, 702 pageURL: window.location.href 703 } 704 }); 705 706 // Extract profile ID safely 707 const CT_profile_id = response?.response_body?.data?.profile?.id; 708 709 // CleverTap Integration (only if profile.id exists) 710 if (CT_profile_id && CT_profile_id !== "") { 711 clevertap.onUserLogin.push({ 712 "Site": { 713 "Identity": CT_profile_id 714 } 715 });
716 } else { 717 console.warn("CleverTap skipped: No valid Profile ID found in response."); 718 } 719 720 clevertap.event.push("registration_success", { 721 firstName: fname, 722 lastName: lname, 723 email: email, 724 phone: phoneNumber, 725 pageURL: window.location.href 726 }); 727 728 //window.location.href = "/plans"; 729 730 //Added By Roshan Starts 731 732 if (window.location.href.indexOf("promo-register") !== -1) { 733 redirectToTargetOrFallback('/promo-plans'); 734 } else { 735 redirectToTargetOrFallback('/plans'); 736 } 737 //Added By Roshan Starts 738 739 } else { 740 $('#otpErr').text(response.message || 'Something went wrong.'); 741 742 AF('pba', 'event', { 743 eventType: 'EVENT', 744 eventName: 'registration_failed', 745 eventValue: { 746 firstName: fname, 747 lastName: lname, 748 email: email, 749 phone: phoneNumber, 750 reason: response.message || 'unknown_error', 751 pageURL: window.location.href 752 } 753 }); 754 755 clevertap.event.push("registration_failed", { 756 firstName: fname, 757 lastName: lname, 758 email: email, 759 phone: phoneNumber, 760 reason: response.message || 'unknown_error', 761 pageURL: window.location.href 762 }); 763 } 764 } catch (e) { 765 console.error("Error parsing response:", e); 766 $('#otpErr').text("An unexpected error occurred. Please try again."); 767 } 768 }, 769 error: function (xhr, status, error) { 770 console.error("AJAX error:", error); 771 $('#otpErr').text("Failed to connect. Please check your internet connection."); 772 773 AF('pba', 'event', { 774 eventType: 'EVENT', 775 eventName: 'registration_failed', 776 eventValue: { 777 phone: phoneNumber, 778 reason: "ajax_error", 779 error_detail: error 780 } 781 }); 782 783 clevertap.event.push("registration_failed", { 784 phone: phoneNumber, 785 reason: "ajax_error", 786 error_detail: error 787 }); 788 } 789 }); 790 } 791 } 792 793 $(document).on("click", ".rf #resend-otp", function () { 794 if ($(this).data('clicked')) { 795 return; // Prevent multiple clicks 796 } 797 798 $(this).data('clicked', true); // Mark as clicked 799 var phoneNumber = $('#phone-number').val(); 800 generateOtp(phoneNumber); 801 $(".otp-input-box").val(""); 802 $("#otpErr").text(""); 803 804 // Optional: Re-enable the button after a certain duration 805 setTimeout(() => { 806 $(this).data('clicked', false); // Allow clicking again 807 }, 5000); 808 }); 809 /******* Script ends for Register Page *******/ 810 811 812 // Select all app download links across site 813 $('.app-download a, .app-store-download-btn a, .pricing-plan-monthly-app-store-download-btn a').on('click', function (e) { 814 var $link = $(this); 815 var store = $link.find('img').attr('alt') || 'App Download'; 816 817 // Get customerUserId from hidden input 818 var customerUserId = $('#hiddenUserContact').val() || null; 819 820 // Fire AppsFlyer event 821 AF('pba', 'event', { 822 eventType: 'EVENT', 823 eventName: 'download_app_clicked', 824 eventValue: { 825 store: store, 826 storeURL: $link.attr('href'), 827 pageURL: window.location.href 828 } 829 }); 830 831 clevertap.event.push("download_app_clicked", { 832 store: store, 833 storeURL: $link.attr('href'), 834 pageURL: window.location.href 835 }); 836 }); 837 838 $('.playQuiz').on('click', function () { 839 clevertap.event.push("og_website_playquiz_clicked", { 840 pageURL: window.location.href 841 }); 842 843 AF('pba', 'event', { 844 eventType: 'EVENT', 845 eventName: 'og_website_playquiz_clicked', 846 eventCategory: 'Contest Page', 847 eventLabel: 'Spot Cyber Threat', 848 eventValue: { 849 pageURL: window.location.href 850 } 851 }); 852 }); 853 854 // Keep all codes here which need to be triggered only once per session 855 const tracked = sessionStorage.getItem("cybx_loaded"); 856 if (!tracked) { 857 clevertap.event.push("website_loaded", { 858 pageURL: window.location.href 859 }); 860 861 AF('pba', 'event', { 862 eventType: 'EVENT', 863 eventName: 'website_loaded', 864 eventValue: { 865 pageURL: window.location.href 866 } 867 }); 868 869 setTimeout(function () { 870 // Clevertap Web Push Notification 871 clevertap.notifications.push({ 872 titleText: "Would you like to receive Push Notifications?", 873 bodyText: "We promise to only send you relevant content and important updates.", 874 okButtonText: "Enable Now", 875 rejectButtonText: "No thanks", 876 okButtonColor: "#F28046", 877 askAgainTimeInSeconds: 10, 878 serviceWorkerPath: "/clevertap_sw.js" 879 }); 880 }, 60000); // 60000 ms = 1 minute 881 882 sessionStorage.setItem("cybx_loaded", "true"); 883 } 884 885 if (window.location.href.includes("insurance-disclaimer")) { // Check if ?insurance-coverage exists 886 var $fancyboxPopup = $('#insurance-disclaimer-popup'); 887 if ($fancyboxPopup.length) { 888 $fancyboxPopup[0].click(); // trigger the popup link 889 } 890 } 891});
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.