1let amplitudeCounter = 0; 2 3const DEVICE_FALLBACK = 1; 4const AMPLITUDE_MAX_RETRIES = 50; 5const AMPLITUDE_RETRY_DELAY = 100; 6 7const JSON_FIELDS = [ 8 'page_current_path', 9 'page_group', 10 'page_url', 11 'page_url_full', 12 'page_http_status_code', 13 'website_domain', 14 'template_id', 15 'template_name', 16 'page_route_id', 17 'last_page', 18 'last_page_source_type', 19 'last_page_source_name', 20 'casino_domain_list', 21 'casino_bonus_id_list', 22 'casino_domain_bonus_id_list', 23 'widget_id', 24 'widget_handler', 25 'widget_section', 26 'widget_position', 27 'casino_list_nodeposit_count', 28 'casino_list_mindeposit_count', 29 'casino_list_label_count', 30 'casino_list_count', 31 'casino_list_casino_unique_count', 32 'casino_list_noafflink_count', 33 'casino_bonus_id', 34 'external_id', 35 'casino_bonus_title_short', 36 'casino_afflink_exist', 37 'casino_bonus_wagering_requirements', 38 'casino_bonus_deposit_min', 39 'casino_bonus_category', 40 'casino_bonus_label', 41 'casino_bonus_type', 42 'casino_bonus_free_spins', 43 'casino_bonus_amount_max', 44 'casino_bonus_percent', 45 'casino_bonus_cashable', 46 'casino_bonus_expired', 47 'casino_bonus_currency', 48 'casino_geo_rating', 49 'casino_bonus_code', 50 'sponsored', 51 'casino_list_nodeposit_position_first', 52 'casino_list_mindeposit_position_first', 53 'casino_list_active_count', 54 'casino_list_active_position_first', 55 'casino_list_noactive_count', 56 'casino_list_noactive_position_first', 57 'casino_list_bonus_code_count', 58 'casino_list_bonus_code_position_first', 59 'casino_list_label_position_first', 60 'sort_newest', 61 'sort_oldest', 62 'sort_highest', 63 'sort_lowest', 64 'promotion_and_bonuses_score', 65 'overall_casino_score', 66 'deposits_and_withdrawals_score', 67 'games_variety_score', 68 'support_score', 69 'website_convenience_score', 70 'casino_domain', 71 'user_id', 72 'widget_title', 73 'widget_template', 74 'widget_list_index', 75 'page_afflink_click_index', 76 'widget_afflink_click_index', 77 'casino_bonus_button_name', 78 'redirect_link', 79 'casino_bonus_slots', 80 'casino_bonus_category_display', 81 'casino_bonus_active_days_left', 82 'casino_bonus_days_after_create', 83 'casino_bonus_exclusive', 84 'review_user_name', 85 'review_user_email', 86 'review_user_rating', 87 'review_liked', 88 'review_disliked', 89 'casino_bonus_active', 90 'reg_placement', 91 'review_id', 92 'website_language', 93 'website_country', 94 'website_environment', 95 'utm_source', 96 'utm_medium', 97 'utm_campaign', 98 'utm_content', 99 'utm_term', 100 'utm_source_init', 101 'utm_medium_init', 102 'utm_campaign_init', 103 'utm_content_init', 104 'utm_term_init', 105 'btn_click_index', 106 'cr_banner_template', 107 'community_option', 108 'authorized', 109 'gamification', 110 'bonus_id', 111 'bonus_title', 112 'casino_name', 113 'bonus_cost', 114 'filter_option', 115 'filter_checked', 116 'total_filters_selected', 117 'reaction_type', 118 'reaction_placement', 119 'chosen_geo', 120 'tooltip_option', 121 'casino_user_country_allowed', 122 'sort_option', 123 'bonus_day', 124 'applied', 125 'bonus_alternatives_trigger', 126]; 127 128const DIRECT_FIELDS = ['event_id', 'event_name', 'event_cat', 'navigation_path']; 129 130const uniqueFields = (...groups) => [...new Set(groups.flat())]; 131 132const PAGE_BASE_FIELDS = [ 133 'event_id', 134 'event_cat', 135 'event_name', 136 'page_current_path', 137 'page_url', 138 'page_group', 139 'page_route_id', 140 'website_domain', 141 'utm_source', 142 'utm_medium', 143 'utm_campaign', 144 'utm_content', 145 'utm_term' 146]; 147 148const UTM_FIELDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term']; 149 150const WIDGET_FIELDS = [ 151 'widget_id', 152 'widget_title', 153 'widget_template', 154 'widget_handler', 155 'widget_section', 156 'widget_position', 157 'bonus_alternatives_trigger' 158]; 159 160const BONUS_FIELDS = [ 161 'casino_domain', 162 'casino_bonus_id', 163 'external_id', 164 'casino_bonus_title_short', 165 'casino_afflink_exist', 166 'casino_bonus_wagering_requirements', 167 'casino_bonus_deposit_min', 168 'casino_bonus_category', 169 'casino_bonus_label', 170 'widget_list_index', 171 'casino_bonus_type', 172 'casino_bonus_free_spins', 173 'page_afflink_click_index', 174 'widget_afflink_click_index', 175 'widget_id', 176 'widget_title', 177 'widget_template', 178 'widget_handler', 179 'widget_section', 180 'widget_position', 181 'casino_bonus_amount_max', 182 'casino_bonus_percent', 183 'casino_bonus_cashable', 184 'casino_bonus_expired', 185 'casino_bonus_button_name', 186 'redirect_link', 187 'casino_bonus_currency', 188 'casino_bonus_active', 189 'casino_bonus_slots', 190 'casino_bonus_category_display', 191 'casino_geo_rating', 192 'casino_bonus_active_days_left', 193 'casino_bonus_days_after_create', 194 'casino_bonus_exclusive', 195 'casino_bonus_code', 196 'casino_user_country_allowed', 197 'sponsored', 198 'bonus_alternatives_trigger' 199]; 200 201const LIST_FIELDS = [ 202 'casino_domain_list', 203 'casino_bonus_id_list', 204 'casino_domain_bonus_id_list', 205 'casino_list_count', 206 'casino_list_casino_unique_count', 207 'casino_list_noafflink_count', 208 'casino_list_nodeposit_count', 209 'casino_list_nodeposit_position_first', 210 'casino_list_mindeposit_count', 211 'casino_list_mindeposit_position_first', 212 'casino_list_active_count', 213 'casino_list_active_position_first', 214 'casino_list_noactive_count', 215 'casino_list_noactive_position_first', 216 'casino_list_bonus_code_count', 217 'casino_list_bonus_code_position_first', 218 'casino_list_label_count', 219 'casino_list_label_position_first' 220]; 221 222const PAYLOADS = { 223 pageBase: PAGE_BASE_FIELDS, 224 pageFull: uniqueFields(PAGE_BASE_FIELDS, ['page_url_full']), 225 pageMeta: uniqueFields(PAGE_BASE_FIELDS, [ 226 'page_http_status_code', 227 'template_id', 228 'template_name', 229 'last_page', 230 'last_page_source_type', 231 'last_page_source_name' 232 ]), 233 authBase: uniqueFields([ 234 'event_cat', 235 'event_name', 236 'page_current_path', 237 'page_url', 238 'page_group', 239 'page_route_id', 240 'website_domain', 241 'reg_placement' 242 ], UTM_FIELDS), 243 widgetBase: uniqueFields(PAGE_BASE_FIELDS, WIDGET_FIELDS), 244 widgetFull: uniqueFields(PAGE_BASE_FIELDS, ['page_url_full'], WIDGET_FIELDS), 245 widgetList: uniqueFields(PAGE_BASE_FIELDS, ['page_url_full'], WIDGET_FIELDS, LIST_FIELDS, ['sponsored']), 246 bonusFull: uniqueFields(PAGE_BASE_FIELDS, ['page_url_full'], BONUS_FIELDS), 247 bonusListFull: uniqueFields(PAGE_BASE_FIELDS, ['page_url_full'], BONUS_FIELDS, LIST_FIELDS), 248 score: uniqueFields([ 249 'event_id', 250 'event_cat', 251 'event_name', 252 'page_url', 253 'page_group', 254 'page_route_id', 255 'overall_casino_score', 256 'promotion_and_bonuses_score', 257 'deposits_and_withdrawals_score', 258 'games_variety_score', 259 'support_score', 260 'website_convenience_score', 261 'casino_domain', 262 'user_id', 263 'website_domain', 264 'widget_handler', 265 'widget_section', 266 'widget_position' 267 ], UTM_FIELDS), 268 gamification: uniqueFields([ 269 'event_cat', 270 'event_name', 271 'page_current_path', 272 'page_url', 273 'page_group', 274 'bonus_id', 275 'external_id', 276 'bonus_title', 277 'casino_domain', 278 'casino_name', 279 'bonus_cost', 280 'user_id', 281 'website_domain', 282 'website_country' 283 ], UTM_FIELDS), 284 userAction: uniqueFields([ 285 'event_id', 286 'event_cat', 287 'event_name', 288 'page_url', 289 'page_group', 290 'page_route_id', 291 'user_id', 292 'website_domain' 293 ], UTM_FIELDS), 294 bonusCalendar: uniqueFields([ 295 'event_id', 296 'event_cat', 297 'event_name', 298 'page_url', 299 'page_group', 300 'page_route_id', 301 'user_id', 302 'website_domain', 303 'sort_option', 304 'bonus_day', 305 'bonus_id' 306 ], UTM_FIELDS) 307}; 308 309const parseJson = (value, fallback = '') => { 310 if (value === undefined || value === null || value === '') return fallback; 311 312 try { 313 return JSON.parse(value); 314 } catch (_) { 315 return value; 316 } 317}; 318 319const pick = (source, fields) => { 320 return fields.reduce((payload, field) => { 321 if (source[field] !== undefined && source[field] !== '') { 322 payload[field] = source[field]; 323 } 324 325 return payload; 326 }, {}); 327}; 328 329const buildContext = (dataLayerEvent = {}) => { 330 const context = { 331 event_id: dataLayerEvent.event_id || 'd-v1-e1', 332 event_name: dataLayerEvent.event_name || '', 333 event_cat: dataLayerEvent.event_cat || '', 334 event_scope: dataLayerEvent.event_scope || '', 335 navigation_path: dataLayerEvent.navigation_path || '' 336 }; 337 338 JSON_FIELDS.forEach((field) => { 339 context[field] = parseJson(dataLayerEvent[field]); 340 }); 341 342 DIRECT_FIELDS.forEach((field) => { 343 context[field] = context[field] ?? dataLayerEvent[field] ?? ''; 344 }); 345 346 const eventScope = context.event_scope || context.event_cat; 347 348 context.formattedEventName = dataLayerEvent.event 349 ? `${dataLayerEvent.event.replace('addEvents_', '')}_[${eventScope}]_${context.event_name}` 350 : ''; 351 352 context.event_name = context.formattedEventName; 353 354 return context; 355}; 356 357const getDeviceInfo = () => { 358 const device_width = window.screen?.width ?? DEVICE_FALLBACK; 359 const device_height = window.screen?.height ?? DEVICE_FALLBACK; 360 const device_ratio = Number((device_width / device_height).toFixed(4)); 361 362 return { device_width, device_height, device_ratio }; 363}; 364 365const logAmplitudeEvent = (eventName, payload) => { 366 amplitude.track(eventName, { 367 ...payload, 368 ...getDeviceInfo() 369 }); 370}; 371 372const makeRule = (match, fields, extraPayload = () => ({})) => ({ match, fields, extraPayload });
373const byName = (part) => ({ formattedEventName }) => formattedEventName.includes(part); 374const byCategory = (category) => ({ event_cat }) => event_cat === category; 375const byNameAndCategory = (part, category) => (context) => byName(part)(context) && byCategory(category)(context); 376const anyName = (parts) => ({ formattedEventName }) => parts.some((part) => formattedEventName.includes(part)); 377const allName = (parts) => ({ formattedEventName }) => parts.every((part) => formattedEventName.includes(part)); 378const groupRule = (eventNameParts, fields, extraPayload) => makeRule(anyName(eventNameParts), fields, extraPayload); 379 380const EVENT_RULES = [ 381 groupRule([ 382 'clickAffLink_[bonus_activate]_casino_visit', 383 'clickAffLink_[pop-up_activate_bonus]_casino_visit', 384 'clickAffLink_[pop-up_activate_superbonus]_casino_visit', 385 'click_[header_hb_banner]_redirect', 386 'click_[drawer_hb_banner]_redirect', 387 'click_[bonus_calendar]_claimed', 388 'click_[event_rules_button]_view' 389 ], PAYLOADS.bonusCalendar), 390 391 groupRule([ 392 'click_[w_website_communityCounter]_register', 393 'click_[w_website_bonusesCounter]_redirect', 394 'click_[w_website_casinosCounter]_redirect', 395 'click_[w_website_trustpilot]_redirect', 396 'click_[w_website_userReviews]_redirect' 397 ], uniqueFields(PAYLOADS.pageFull, ['widget_id'])), 398 399 groupRule([ 400 'showWidget_[w_casinoScoreWidget]_view', 401 'click_[w_casinoScoreWidget]_tipHonestReviews', 402 'click_[w_casinoScoreWidget]_writeReview' 403 ], PAYLOADS.score), 404 405 groupRule([ 406 'click_[w_writeReviewPopup]_1stStep', 407 'click_[w_writeReviewPopup]_2stStep', 408 'click_[w_writeReviewPopup]_submitReview' 409 ], PAYLOADS.score), 410 411 groupRule([ 412 'click_[w_writeReviewWidget]_writeReview', 413 'click_[w_writeReviewWidget]_1stStep', 414 'click_[w_writeReviewWidget]_2stStep', 415 'click_[w_writeReviewWidget]_submitReview' 416 ], PAYLOADS.score), 417 418 groupRule([ 419 'w_website_gamification', 420 'p_profile_rewards', 421 'p_profile_reviews', 422 'p_profile_shop', 423 'p_shop_popup', 424 'w_website_telegram_Popup' 425 ], PAYLOADS.gamification), 426 427 groupRule([ 428 'click_[w_userReview]_like', 429 'click_[w_userReview]_showMore', 430 'click_[summaryIWidget]_userReviews' 431 ], uniqueFields(PAYLOADS.userAction, ['review_id', 'casino_domain'])), 432 433 groupRule([ 434 'registration_[w_website]_new_user', 435 'registration_[drawer_hb_banner]_new_user', 436 'registration_[w_website_google_oneTap]_new_user' 437 ], uniqueFields([ 438 'event_id', 439 'event_cat', 440 'event_name', 441 'page_url', 442 'page_group', 443 'user_id', 444 'page_current_path', 445 'gamification', 446 'reg_placement', 447 'website_domain' 448 ], UTM_FIELDS)), 449 450 groupRule([ 451 'click_[filterBar]_filter', 452 'click_[sortBar]_sort' 453 ], PAYLOADS.userAction), 454 455 makeRule(byName('visitPage'), PAYLOADS.pageMeta), 456 makeRule(byName('click_[geo_Selection]_view'), uniqueFields(PAYLOADS.pageFull, ['reg_placement'])), 457 makeRule(byName('click_[geo_Selection]_choice'), uniqueFields(PAYLOADS.pageFull, ['reg_placement', 'chosen_geo'])), 458 makeRule(byCategory('geo_country_rejection'), PAYLOADS.pageFull), 459 makeRule(byName('showBlock_[w_website_gamification_registration_popup]_open'), uniqueFields(PAYLOADS.pageFull, ['reg_placement'])), 460 makeRule(byName('showWidget_[w_website]_footer'), uniqueFields(['event_id', 'event_cat', 'event_name', 'page_current_path', 'page_url', 'page_group', 'website_domain'], UTM_FIELDS)), 461 makeRule(byName('showWidget_[w_website]_comment'), uniqueFields(PAYLOADS.pageBase, ['widget_handler', 'widget_section', 'widget_position'])), 462 makeRule(byName('showBlock_[w_website_userReviews]_view'), uniqueFields(PAYLOADS.pageBase, ['widget_handler', 'widget_section', 'widget_position'])), 463 makeRule(byName('click_[w_website_navigation]_redirect'), uniqueFields(PAYLOADS.pageBase, ['widget_id', 'navigation_path'])), 464 makeRule(byName('click_[subscribe_block]_subscribe'), uniqueFields(PAYLOADS.pageBase)), 465 makeRule(byName('showWidget_[w_userReview]_view'), uniqueFields(PAYLOADS.userAction, ['casino_domain', 'review_id'])), 466 makeRule(byName('click_[w_commentSection]_sort'), uniqueFields(['event_id', 'event_cat', 'event_name', 'page_url', 'page_group', 'page_route_id', 'sort_newest', 'sort_oldest', 'sort_highest', 'sort_lowest', 'website_domain'], UTM_FIELDS)), 467 makeRule(byName('login_[w_website]_existing_user'), uniqueFields(['event_id', 'event_cat', 'event_name', 'page_url', 'user_id', 'page_current_path'], UTM_FIELDS)), 468 makeRule(byCategory('w_website_placement_banner_feed'), uniqueFields(PAYLOADS.pageBase, ['widget_handler', 'widget_section', 'widget_position'])), 469 makeRule(byCategory('w_website_placement_communityBanner_feed'), uniqueFields(PAYLOADS.pageBase, ['widget_handler', 'widget_section', 'widget_position']), ({ community_option }) => (community_option ? { community_option } : {})), 470 makeRule(byNameAndCategory('showBlock', 'w_website_sponsored_bonus_menu'), PAYLOADS.bonusListFull), 471 makeRule(byNameAndCategory('clickAffLink', 'w_website_sponsored_bonus_menu'), PAYLOADS.bonusFull), 472 makeRule(byName('showWidget_[activity_log]_view'), PAYLOADS.widgetFull), 473 makeRule(byName('click_[activity_log]_show_more'), PAYLOADS.widgetFull), 474 makeRule(byName('clickAffLink_[activity_log]_redirect'), PAYLOADS.bonusFull), 475 makeRule(byName('showBlock_[w_bonus_list_tooltip]_view'), uniqueFields(PAYLOADS.bonusFull, ['tooltip_option'])), 476 makeRule(byName('click_[w_website]_comment'), uniqueFields(PAYLOADS.widgetBase, ['review_user_name', 'review_user_email', 'review_user_rating', 'review_liked', 'review_disliked'])), 477 makeRule(byName('click_[w_website]_showMore'), uniqueFields(PAYLOADS.widgetBase, ['btn_click_index'])), 478 makeRule(byName('click_[w_website_wheels_exit_popup]_submit'), uniqueFields(PAYLOADS.pageBase, [ 479 'authorized', 480 'casino_domain_list', 481 'casino_bonus_id_list', 482 'casino_domain_bonus_id_list', 483 'casino_list_count', 484 'casino_list_casino_unique_count', 485 'casino_list_noafflink_count' 486 ])), 487 makeRule(byName('clickAffLink'), PAYLOADS.bonusFull), 488 makeRule(byName('clickPromoCode'), PAYLOADS.bonusFull), 489 makeRule(allName(['showBlock', 'tc_open']), PAYLOADS.bonusFull), 490 makeRule(byName('click_[filtersMenu]_checkbox'), uniqueFields(PAYLOADS.userAction, ['filter_option', 'filter_checked'])), 491 makeRule(byName('click_[filtersMenu]_applyBtn'), uniqueFields(PAYLOADS.userAction, ['total_filters_selected'])), 492 makeRule(byName('click_[filterBar_option]_apply'), uniqueFields(PAYLOADS.userAction, ['total_filters_selected', 'applied'])), 493 makeRule(byName('click_[sortBar]_apply'), uniqueFields(PAYLOADS.userAction, ['sort_option'])), 494 makeRule(byName('click_[bonusReaction]_submit'), uniqueFields(PAYLOADS.widgetFull, [ 495 'casino_domain', 496 'casino_bonus_id', 497 'casino_bonus_title_short', 498 'widget_list_index', 499 'reaction_type', 500 'reaction_placement', 501 'casino_afflink_exist', 502 'casino_bonus_wagering_requirements', 503 'casino_bonus_deposit_min', 504 'casino_bonus_category', 505 'casino_bonus_label', 506 'casino_bonus_type', 507 'casino_bonus_free_spins', 508 'casino_bonus_expired', 509 'sponsored' 510 ])), 511 makeRule( 512 ({ formattedEventName, event_cat }) => 513 (formattedEventName.includes('showWidget') && event_cat !== 'w_website_LowCrBanner') || 514 ( 515 formattedEventName.includes('showBlock') && 516 !formattedEventName.includes('tc_open') && 517 ![ 518 'w_website_search_form_popup', 519 'w_website_email_popup', 520 'w_website_email', 521 'w_website_placement_banner_feed', 522 'w_website_placement_communityBanner_feed', 523 'w_website_regtypes', 524 'w_website_password', 525 'w_website_email_confirm' 526 ].includes(event_cat) 527 ), 528 PAYLOADS.widgetList 529 ) 530]; 531 532const findEventRule = (context) => EVENT_RULES.find((rule) => rule.match(context)); 533 534const processDataLayerEvent = (dataLayerEvent = {}) => { 535 const context = buildContext(dataLayerEvent); 536 537 if (!context.formattedEventName) return; 538 539 const rule = findEventRule(context); 540 541 if (rule) { 542 logAmplitudeEvent(context.formattedEventName, { 543 ...pick(context, rule.fields), 544 ...rule.extraPayload(context) 545 }); 546 } 547 548 if (dataLayerEvent.event?.includes('addUserProperties')) { 549 uploadUserProperties({ 550 website_language: context.website_language, 551 website_country: context.website_country, 552 website_environment: context.website_environment, 553 utm_source_init: context.utm_source_init, 554 utm_medium_init: context.utm_medium_init, 555 utm_campaign_init: context.utm_campaign_init,
556 utm_content_init: context.utm_content_init, 557 utm_term_init: context.utm_term_init 558 }); 559 } 560}; 561 562let processedEventCount = 0; 563 564const callEvents = () => { 565 while (processedEventCount < dataLayer.length) { 566 const dataLayerEvent = dataLayer[processedEventCount]; 567 processedEventCount += 1; 568 569 try { 570 processDataLayerEvent(dataLayerEvent); 571 } catch (error) { 572 console.log('Error in callEvents', error); 573 } 574 } 575}; 576 577const detectEventsPush = () => { 578 if (!window.dataLayer || !Array.isArray(window.dataLayer)) { 579 window.dataLayer = []; 580 } 581 582 if (window.dataLayer.__amplitudePushDetected) return; 583 584 const originalPush = window.dataLayer.push; 585 586 window.dataLayer.push = (...args) => { 587 const result = originalPush.apply(window.dataLayer, args); 588 callEvents(); 589 return result; 590 }; 591 592 window.dataLayer.__amplitudePushDetected = true; 593}; 594 595const safeGetAmplitudeDeviceId = () => { 596 try { 597 return amplitude.getDeviceId() ?? window.getAmplitudeDeviceId?.() ?? null; 598 } catch (_) { 599 return window.getAmplitudeDeviceId?.() ?? null; 600 } 601}; 602 603const uploadUserProperties = (properties = {}) => { 604 const identify = new amplitude.Identify() 605 .set('website_language', properties.website_language) 606 .set('website_country', properties.website_country) 607 .set('website_environment', properties.website_environment) 608 .set('is_test', properties.is_test) 609 .set('utm_source_init', properties.utm_source_init) 610 .set('utm_medium_init', properties.utm_medium_init) 611 .set('utm_campaign_init', properties.utm_campaign_init) 612 .set('utm_content_init', properties.utm_content_init) 613 .set('utm_term_init', properties.utm_term_init) 614 .set('device_id', safeGetAmplitudeDeviceId()); 615 616 amplitude.identify(identify); 617}; 618 619const amplitudeSdkSearch = () => { 620 if (window.amplitude) { 621 setTimeout(() => callEvents(), AMPLITUDE_RETRY_DELAY); 622 return; 623 } 624 625 if (amplitudeCounter < AMPLITUDE_MAX_RETRIES) { 626 amplitudeCounter += 1; 627 setTimeout(amplitudeSdkSearch, AMPLITUDE_RETRY_DELAY); 628 } 629}; 630 631setTimeout(detectEventsPush, AMPLITUDE_RETRY_DELAY); 632amplitudeSdkSearch();
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.