1function initAnalytics() 2{ 3 docReady(function () { 4 initMobile(); 5 6 $('[data-stats]').each(function () { 7 initAnalyticsPlugins($(this)); 8 }); 9 10 initCrtnObservers(); 11 12 $('[data-stats-custom]').each(function() { 13 initStatsCustomCommon($(this)); 14 }) 15 }); 16 17 function initAnalyticsPlugins(elem) 18 { 19 var plugins = elem.attr('data-stats').split('|'); 20 for (var i = 0; i < plugins.length; i++) { 21 initAnalyticsPlugin(elem, plugins[i]); 22 } 23 } 24 25 26 function initAnalyticsPlugin(elem, plugin) 27 { 28 switch (plugin) { 29 30 case 'quickLinkDefault': 31 initQuickLinkDefault(elem); 32 break; 33 34 case 'quickLinkCircle': 35 initQuickLinkCircle(elem); 36 break; 37 38 case 'quickLinkToggleButton': 39 initQuickLinkToggleButton(elem); 40 break; 41 42 case 'googleMaps': 43 initGoogleMaps(elem); 44 break; 45 46 case 'pagePassword': 47 initPagePassword(elem); 48 break; 49 50 case 'detailsLabels': 51 initVehicleLabels(elem); 52 break; 53 54 case 'crtnButton': 55 initCrtnButton(elem); 56 break; 57 58 case 'crtnToggle': 59 initCrtnToggle(elem); 60 break; 61 62 case 'proposition': 63 initDesktopPropositions(elem); 64 break; 65 66 default: 67 initStatsCustom(elem); 68 break; 69 } 70 } 71 72 // for layout-level stats or custom html from static texts 73 // example <a href="#0" data-stats="custom" data-event-category="Header makes" data-event-action="click">test</a> 74 function initStatsCustom(elem) { 75 var data = elem.data(), 76 trigger = elem.eventTrigger || 'click', 77 cat = data.eventCategory, 78 action = elem.eventAction || elem.attr('data-event-action'), 79 label = elem.eventLabel, 80 value = elem.eventValue, 81 fieldsObject = { 82 hitType: 'event', 83 eventCategory: cat, 84 eventAction: action 85 }; 86 87 if (cat && action) { 88 if (label) $.extend(fieldsObject, { eventLabel: label }); 89 if (value) $.extend(fieldsObject, { eventValue: value }); 90 elem.on(trigger, function () { 91 ev('send', fieldsObject); 92 }); 93 } 94 } 95 96 97 function initQuickLinkDefault (elem) 98 { 99 elem.click(function () { 100 ev('send', { 101 hitType: 'event', 102 eventCategory: 'Quick links', 103 eventAction: 'Click', 104 eventLabel: 'Quick link aside', 105 eventValue: $.trim(elem.text()) 106 }); 107 108 if (elem.closest('.item.whatsapp').length) { 109 ev('send', { 110 hitType: 'event', 111 eventCategory: 'WhatsApp buttons', 112 eventAction: 'click', 113 eventLabel: 'quicklinks_default_button' 114 }); 115 } 116 }) 117 } 118 119 120 function initQuickLinkCircle (elem) 121 { 122 elem.click(function () { 123 ev('send', { 124 hitType: 'event', 125 eventCategory: 'Quick links', 126 eventAction: 'Click', 127 eventLabel: 'Request callback' 128 }); 129 }); 130 } 131 132 133 function initQuickLinkToggleButton (elem) 134 { 135 elem 136 .one('mouseenter', function () { 137 ev('send', { 138 hitType: 'event', 139 eventCategory: 'Quick link toggle button', 140 eventAction: 'Hover', 141 eventLabel: 'Opening quicklinks by hovering' 142 }); 143 }) 144 .one('click', function () { 145 ev('send', { 146 hitType: 'event', 147 eventCategory: 'Quick link toggle button', 148 eventAction: 'Click', 149 eventLabel: 'Opening quicklinks by touch/click' 150 }); 151 }); 152 153 $('.quicklink', elem.closest('.links-container')).each(function () { 154 $(this).one('click', function () { 155 var label_key = $(this).data('stats-key'); 156 ev('send', { 157 hitType: 'event', 158 eventCategory: 'Quick link toggle button', 159 eventAction: 'Toggle button item click', 160 eventLabel: 'Clicking on ' + label_key + ' button', 161 eventValue: window.location.href 162 }); 163 }); 164 }); 165 } 166 167 168 function initGoogleMaps (elem) 169 { 170 $('#js-push', elem).one('click', function () { 171 ev('send', { 172 hitType: 'event', 173 eventCategory: 'GoogleMaps', 174 eventAction: 'Click', 175 eventLabel: 'Open directions input' 176 }); 177 }); 178 179 $('#js-refresh-map', elem).one('click', function () { 180 ev('send', { 181 hitType: 'event', 182 eventCategory: 'GoogleMaps', 183 eventAction: 'Click', 184 eventLabel: 'Submit directions input' 185 }); 186 }); 187 } 188 189 190 function initPagePassword (elem) 191 { 192 $('[type="submit"]', elem).one('click', function () { 193 ev('send', { 194 hitType: 'event', 195 eventCategory: 'PagePassword', 196 eventAction: 'Click', 197 eventLabel: 'Submit form on protected page', 198 eventValue: window.location.href 199 }); 200 }); 201 } 202 203 204 function initVehicleLabels (elem) 205 { 206 $('[href="#video-modal"]', elem).one('click', function () { 207 ev('send', { 208 hitType: 'event', 209 eventCategory: 'Desktop details', 210 eventAction: 'Click', 211 eventLabel: 'Vehicle video modal opening', 212 eventValue: window.location.href 213 }); 214 }); 215 216 $(document).one('viewVehicleVideo', function () { 217 ev('send', { 218 hitType: 'event', 219 eventCategory: 'Desktop details', 220 eventAction: 'HashAutorun', 221 eventLabel: 'Vehicle video modal opening', 222 eventValue: window.location.href 223 }); 224 }); 225 } 226 227 228 function initCrtnButton (elem) 229 { 230 elem.click(function (event) { 231 var route = document._route || 'Unknown' 232 233 if ($('body.is-home').length) { 234 route = 'Homepage' 235 } 236 237 ev('send', { 238 hitType: 'event', 239 eventCategory: 'Caratana', 240 eventAction: 'Click on desktop', 241 eventLabel: route 242 }); 243 }); 244 } 245 246 247 function initCrtnToggle (elem) 248 { 249 elem.click(function (event) { 250 var route = document._route || 'Unknown' 251 252 if ($('body.is-home').length) { 253 route = 'Homepage' 254 } 255 256 ev('send', { 257 hitType: 'event', 258 eventCategory: 'Caratana',
259 eventAction: 'Toggle on desktop', 260 eventLabel: route 261 }); 262 }); 263 } 264 265 function initDesktopPropositions(elem) 266 { 267 elem.find('a').each(function() { 268 var a = $(this), 269 label = a.attr('title'); 270 271 ev('send', { 272 hitType: 'event', 273 eventCategory: 'Desktop Angebote', 274 eventAction: 'Click on an angebot item', 275 eventLabel: label, 276 }); 277 }) 278 } 279 280 function initCrtnObservers() 281 { 282 if ('IntersectionObserver' in window && 283 'IntersectionObserverEntry' in window && 284 'intersectionRatio' in window.IntersectionObserverEntry.prototype) { 285 $(window).load(function() { 286 $('.crtn-eyecatcher, .crtn-global, .crtn-context, .crtn-compact').each(function() { 287 initObserver(this); 288 }); 289 }); 290 } 291 } 292 293 function initObserver(target) 294 { 295 if (target.io) return; 296 target.io = new IntersectionObserver(function(entries) { 297 entries.forEach(function(entry) { 298 if (entry.isIntersecting) { 299 var cls = entry.target.className.split(' ').shift(), 300 route = document._route || 'Unknown', 301 platform = document.is_mobile ? '_mobile' : '', 302 evtLabel = route+platform+'--'+cls; 303 304 if (entry.target.hasIntersected) return; 305 entry.target.hasIntersected = true; 306 307 ev('send', { 308 hitType: 'event', 309 eventCategory: 'Caratana', 310 eventAction: 'Banner Intersection', 311 eventLabel: evtLabel 312 }); 313 } 314 }) 315 }, {threshold: 0.8}); 316 target.io.observe(target); 317 } 318 319 320 321 // ********************************* Mobile ********************************* 322 323 324 325 function initMobile () 326 { 327 $(window).load(function(){ 328 329 // init mobile layout 330 initDropdownMenu(); 331 initButtonBack(); 332 initButtonSearch(); 333 334 // init mobile widgets 335 initMobileVideoButton(); 336 initMobileLangSwitcher(); 337 initMobileLShareButtons(); 338 initMobilePagePassword(); 339 340 // init integrations 341 initMobileCrtnButtons(); 342 initMobilePropositions(); 343 344 $('[data-stats-custom]').each(function() { 345 initStatsCustomCommon($(this)); 346 }) 347 }); 348 349 // layout 350 351 function initDropdownMenu() { 352 $('select.dropdown-mobile-menu', '.top-bar, .topbar').prev().click(function () { 353 ev('send', { 354 hitType: 'event', 355 eventCategory: 'Mobile layout', 356 eventAction: 'Click', 357 eventLabel: 'Dropdown menu' 358 }); 359 }); 360 } 361 362 function initButtonBack() { 363 $('.btn-previous-page', '.top-bar, .topbar').click(function () { 364 ev('send', { 365 hitType: 'event', 366 eventCategory: 'Mobile layout', 367 eventAction: 'Click', 368 eventLabel: 'Back button' 369 }); 370 }); 371 } 372 373 function initButtonSearch() { 374 $('[href="#isa_panel"]', '.top-bar, .topbar').click(function () { 375 ev('send', { 376 hitType: 'event', 377 eventCategory: 'Mobile layout', 378 eventAction: 'Click', 379 eventLabel: 'Search button' 380 }); 381 }); 382 } 383 384 // mobile widgets 385 386 function initMobileVideoButton () 387 { 388 $('[data-stats="mobileVideoButton"]').click(function (event) { 389 event.preventDefault(); 390 ev('send', { 391 hitType: 'event', 392 eventCategory: 'Mobile details', 393 eventAction: 'Click on Video', 394 eventLabel: $.trim($('.title', $(this).closest('.details-page')).eq(0).text()) 395 }); 396 window.location.href = $(this).attr('href'); 397 }); 398 } 399 400 function initMobileLangSwitcher () 401 { 402 $(document).on('click', '.ui-btn:has([data-id="lang-switcher"])', function (event) { 403 event.preventDefault(); 404 ev('send', { 405 hitType: 'event', 406 eventCategory: 'Mobile layout', 407 eventAction: 'Click', 408 eventLabel: 'Language switcher button' 409 }); 410 }); 411 } 412 413 function initMobileLShareButtons () 414 { 415 $('> a', '.socials-mobile, .socials-mobile-gallery').click(function (event) { 416 ev('send', { 417 hitType: 'event', 418 eventCategory: 'SocialButtons', 419 eventAction: 'share', 420 eventLabel: $(this).attr('data-ga-label') 421 }); 422 }); 423 } 424 425 function initMobilePagePassword () 426 { 427 $('.submit-mobile', '.widget-pagepassword').one('click', function () { 428 ev('send', { 429 hitType: 'event', 430 eventCategory: 'PagePassword', 431 eventAction: 'Click', 432 eventLabel: 'Submit form on protected page', 433 eventValue: window.location.href 434 }); 435 }); 436 } 437 438 function initMobileCrtnButtons () 439 { 440 $('[data-stats="crtnButton"], .crtn-button').click(function (event) { 441 ev('send', { 442 hitType: 'event', 443 eventCategory: 'Caratana', 444 eventAction: 'Click on mobile', 445 eventLabel: document._route || 'Unknown' 446 }); 447 }); 448 449 $('[data-stats="crtnToggle"]').click(function (event) { 450 ev('send', { 451 hitType: 'event', 452 eventCategory: 'Caratana', 453 eventAction: 'Toggle on mobile', 454 eventLabel: document._route || 'Unknown' 455 }); 456 }); 457 } 458 459 function initMobilePropositions () 460 { 461 $('.widget-propositions .preview a').click(function (event) { 462 var label = $(this).text().trim() || $(this).attr('title') 463 ev('send', { 464 hitType: 'event', 465 eventCategory: 'Mobile Angebote', 466 eventAction: 'Click on an angebot item', 467 eventLabel: label, 468 }); 469 }); 470
471 $('.widget-propositions-details [onclick*="scrollToPropositionForm"]').click(function (event) { 472 ev('send', { 473 hitType: 'event', 474 eventCategory: 'Mobile Angebote', 475 eventAction: 'Scroll to form', 476 eventLabel: document.title, 477 }); 478 }); 479 } 480 } 481 482 function initStatsCustomCommon(elem) { 483 if (elem.data('is-inited')) { 484 return; 485 } 486 487 var data = elem.data(), 488 trigger = data.eventTrigger || elem.attr('data-event-trigger') || 'click', 489 cat = data.eventCategory || elem.attr('data-event-category'), 490 action = data.eventAction || elem.attr('data-event-action'), 491 label = data.eventLabel || elem.attr('data-event-label'), 492 value = data.eventValue || elem.attr('data-event-value'), 493 fieldsObject = { 494 hitType: 'event', 495 eventCategory: cat, 496 eventAction: action 497 }; 498 499 if (cat && action) { 500 if (label) $.extend(fieldsObject, { eventLabel: label }); 501 if (value) $.extend(fieldsObject, { eventValue: value }); 502 elem.on(trigger, function () { 503 ev('send', fieldsObject); 504 }); 505 } else { 506 console.log('No category or action. Event is aborted.') 507 } 508 509 elem.data('is-inited', true) 510 } 511 512 // proxy for 'universal analytics' and GA4 513 function ev(command, fieldsObject) 514 { 515 if (typeof ga === "function") { 516 // console.log('ga exists and is going to send ', fieldsObject); 517 ga(command, fieldsObject); 518 $(document).trigger('statsSent'); 519 } else if (typeof gtag === "function") { 520 gtag('event', fieldsObject.eventAction, { 521 event_category: fieldsObject.eventCategory, 522 event_label: fieldsObject.eventLabel, 523 }); 524 } 525 } 526} 527 528initAnalytics();
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.