1class AltimaxGtm { 2 constructor() { 3 let _instance = this 4 _instance.cookie_domain = [""] 5 _instance.cookie_path = "\/" 6 _instance.cookie_duration = 3600 7 _instance.cookie_name = "alticrm_data" 8 9 // set custom dimensions from cookie 10 _instance.triggerDataLayerSetDimensions() 11 12 // trigger page view event 13 _instance.triggerDataLayerPageView() 14 15 // add dimension to cookie 16 jQuery('.__gtm_add_dimension_cookie').click(function () { 17 let _this = jQuery(this) 18 _instance.addDimensionCookie(_this.data('type'), _this.data('libelle')) 19 }) 20 21 // add dimension to cookie select 22 jQuery('.__gtm_add_dimension_cookie_select').change(function () { 23 let _this = jQuery(this) 24 _instance.addDimensionCookie(_this.data('type'), _this.children(':selected').data('libelle')) 25 }) 26 27 // track clic 28 jQuery('.__gtm_track_click').click(function () { 29 let _this = jQuery(this) 30 _instance.constructor.triggerDataLayerPush(_this.data('event-category'), _this.data('event-action'), _this.data('event-label'), 'Event clic') 31 }) 32 33 // track form 34 jQuery('.__gtm_track_form').submit(function () { 35 let _this = jQuery(this) 36 _instance.constructor.triggerDataLayerPush(_this.data('event-category'), _this.data('event-action'), _this.data('event-label'), 'Event contact form') 37 }) 38 39 // track listing items 40 let $items = jQuery('#js-apidae-items-container').find('.ApidaeListingItem') 41 _instance.constructor.bindApidaeListingItemsView($items) 42 43 jQuery('.__altimax_gtm_data_layer').each(function () { 44 let crm = _this.data('crm') 45 if (crm) 46 _instance.constructor.triggerDataLayerPush(crm.category, crm.action, crm.label, crm.event) 47 }) 48 } 49 50 /** 51 * add GTM event to datalayer 52 * 53 * @param category string 54 * @param action string 55 * @param label string 56 * @param event string 57 */ 58 static triggerDataLayerPush(category, action, label, event) { 59 window.dataLayer = window.dataLayer || [] 60 window.dataLayer.push({ 61 'eventCategory': category, 62 'eventAction': action, 63 'eventLabel': label, 64 'event': event 65 }) 66 } 67 68 /** 69 * add GTM custom dimension to datalayer 70 * 71 * @param dimension 72 * @param value 73 */ 74 static triggerDataLayerDimension(dimension, value) { 75 window.dataLayer = window.dataLayer || [] 76 let obj = {} 77 obj[dimension] = value 78 dataLayer.push(obj) 79 } 80 81 /** 82 * add GTM custom dimensions to datalayer 83 * get Type Client, Activite, Periode from cookie 84 * and Type Page from js let alticrm 85 */ 86 triggerDataLayerSetDimensions() { 87 let _instance = this 88 window.dataLayer = window.dataLayer || [] 89 let obj = {} 90 91 // get data from cookie 92 let cookieData = AltimaxCookie.readCookie(_instance.cookie_name) 93 if (cookieData) { 94 try { 95 cookieData = JSON.parse(cookieData) 96 let activite = [] 97 // parse cookieData keys 98 for (let key in cookieData) { 99 if ('type_client' == key && typeof cookieData[key].nom !== 'undefined') 100 obj['profilTypeClient'] = cookieData[key].nom 101 if ('activite' == key.substring(0, 8) && typeof cookieData[key].nom !== 'undefined') 102 activite.push(cookieData[key].nom) 103 } 104 if (activite.length > 0) 105 obj['profilActivite'] = this.constructor.uniq(activite).join(', ') 106 107 if (typeof cookieMonth !== 'undefined') { 108 let month = AltimaxCookie.readCookie(cookieMonth) 109 if (month) 110 obj['profilPeriode'] = month + ' ' + this.constructor.getTtrackingMonth(month) 111 } 112 } catch (e) { 113 } 114 } 115 116 // get data from post id 117 if (typeof window.typologie_page !== 'undefined') 118 obj['profilTypePage'] = window.typologie_page 119 120 121 dataLayer.push(obj) 122 } 123 124 /** 125 * trigger custom event "pageview" 126 * we need to trigger this custom event in order to have custom dimensions 127 * the original one in GTM is firing too soon (before DOM Ready) 128 */ 129 triggerDataLayerPageView() { 130 window.dataLayer = window.dataLayer || [] 131 window.dataLayer.push({ 132 'event': 'pageview' 133 }) 134 } 135 136 static uniq(a) { 137 return a.sort().filter(function (item, pos, ary) { 138 return !pos || item != ary[pos - 1] 139 }) 140 } 141 142 static getTtrackingMonth(month) { 143 let trackingMonth = { 144 '01': 'Janvier', 145 '02': 'Février', 146 '03': 'Mars', 147 '04': 'Avril', 148 '05': 'Mai', 149 '06': 'Juin', 150 '07': 'Juillet', 151 '08': 'Août', 152 '09': 'Septembre', 153 '10': 'Octobre', 154 '11': 'Novembre', 155 '12': 'Décembre' 156 } 157 158 return trackingMonth[month] 159 } 160 161 /** 162 * add custom dimension to cookie 163 * 164 * @param type 165 * @param libelle 166 */ 167 addDimensionCookie(type, libelle) { 168 let cookieExpireTime = this.cookie_duration 169 let cookieData = AltimaxCookie.readCookie(this.cookie_name) 170 let countActivite = 1 171 if (cookieData) { 172 cookieData = JSON.parse(cookieData) 173 // parse cookieData keys to find max activite key 174 for (let key in cookieData) 175 if ('activite' == key.substring(0, 8)) 176 countActivite = parseInt(key.substring(8), 10) + 1 177 } else 178 cookieData = {} 179 180 181 let key = (type == 'activite') ? 'activite' + countActivite : type 182 183 if (cookieData[key] == undefined) 184 cookieData[key] = {} 185 186 cookieData[key]['nom'] = libelle 187 AltimaxCookie.writeCookie(this.cookie_name, JSON.stringify(cookieData), cookieExpireTime) 188 } 189 190 static bindApidaeListingItemsView(items) { 191 let _instance = this 192 if (items.length) 193 jQuery(items).each(function () { 194 let _this = jQuery(this) 195 _instance.triggerDataLayerPush(_this.data('event-category'), _this.data('event-action'), _this.data('event-label'), 'Event vue') 196 }) 197 198 } 199} 200 201jQuery(document).ready(function () { 202 window.AltimaxGtm = new AltimaxGtm() 203});
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.