1//get parent details 2function getParentCategory(parentEl) { 3 var cls = parentEl.classList, 4 parentCategory; 5 switch (true) { 6 case cls.contains('proofreading') || cls.contains('proofreading-tools'): 7 parentCategory = 'proofreading'; 8 break; 9 case cls.contains('plagiarismcheck') || cls.contains('plagiarism-tools'): 10 parentCategory = 'plagiarism'; 11 break; 12 case cls.contains('citation') || cls.contains('citation-tools'): 13 parentCategory = 'citation tool'; 14 break; 15 case cls.contains('ai-writing') || cls.contains('ai-tools'): 16 parentCategory = 'ai tools'; 17 break; 18 default: 19 parentCategory = 'knowledgebase'; 20 } 21 return parentCategory; 22} 23//get upload button location by class 24function getLocationByClass(buttonElement) { 25 var cls = buttonElement.classList, 26 buttonLocation; 27 switch (true) { 28 case cls.contains('btn--upload'): 29 case cls.contains('dropdown__link'): 30 buttonLocation = 'header'; 31 break; 32 case cls.contains('btn--primary'): 33 buttonLocation = 'primary button'; 34 break; 35 case cls.contains('btn--secondary'): 36 buttonLocation = 'secondary button'; 37 break; 38 default: 39 buttonLocation = 'other'; 40 } 41 return buttonLocation; 42} 43 44//track citation free checker opened 45window.addEventListener('load', (event) => { 46 if (typeof bindButtons === 'function') { 47 let citChkButtons = document.querySelectorAll(`a.btn--white, a.ts-cc`); 48 citChkButtons.forEach(function(elem){ 49 elem.addEventListener('click', function(){ 50 marketing.trackEvent('Citation Free Checker Opened').sendToAmplitude(); // send to amplitude 51 }) 52 }); 53 } 54}); 55 56//onclick simple page events 57function sendAmpliEvent(eventName) { 58 marketing.trackEvent(eventName).sendToAmplitude(); // send to amplitude 59} 60 61//add click event to service links 62function addKBServicesClickEvents() { 63 var linkType, 64 elem = this, 65 itemService; 66 if (elem.dataset.serviceName) { 67 itemService = elem.dataset.serviceName; 68 } 69 if (elem.dataset.serviceLocation) { 70 linkType = elem.dataset.serviceLocation; 71 } else if (elem.closest('div.cta-services').classList.contains('style-vertical')) { 72 linkType = 'sidebar'; 73 } else if (elem.closest('div.cta-services').classList.contains('style-horizontal')) { 74 linkType = 'header'; 75 } else if (elem.closest('div.scw').classList.contains('scw-location-exit_intent')) { 76 linkType = 'exit_intent'; 77 } else { 78 linkType = 'in_text'; 79 } 80 var linkURL = elem.getAttribute('href').split('?')[0], 81 serviceCopy = ''; 82 if (elem.getElementsByTagName('H3')[0]) { 83 serviceCopy = elem.getElementsByTagName('H3')[0].innerText; 84 } 85 86 var eventProperties = { 87 "adId": elem.dataset.adId || 0, 88 "ad_type": linkType, 89 "location_url": ampliCurrentURL, 90 "outgoing_url": linkURL, 91 "service": itemService, 92 "ad_copy": serviceCopy 93 }; 94 marketing.trackEvent('Ad Clicked Knowledge Base', eventProperties).sendToAmplitude(); // send to amplitude 95} 96//remove click event from service links 97function reinitiateKBServicesClickEvents() { 98 let servicesLinks = document.querySelectorAll(`.cta-services a, .scw-location-in_text a, .scw-location-exit_intent a`); 99 servicesLinks.forEach(function (elem) { 100 elem.removeEventListener("click", addKBServicesClickEvents); 101 elem.addEventListener("click", addKBServicesClickEvents); 102 }); 103} 104 105//subnav clicked 106let subNavItems = document.querySelectorAll(`.sub-nav .nav__list a`); 107subNavItems.forEach(function (elem) { 108 elem.addEventListener("click", function () { 109 //main item 110 var mainItem = elem.innerText, 111 itemURL = elem.getAttribute('href'); 112 var eventProperties = { 113 "main_item": mainItem, 114 "destination_url": itemURL, 115 "location_url": ampliCurrentURL 116 }; 117 marketing.trackEvent('Sub Header Clicked', eventProperties).sendToAmplitude(); // send to amplitude 118 119 }); 120}); 121 122window.addEventListener('load', (event) => { 123 //if knowledgebase target service and document download
124 if (document.body.classList.contains('knowledgebase')) { 125 let servicesLinks = document.querySelectorAll(`.cta-services a, .scw-location-in_text a, .scw-location-exit_intent a`); 126 servicesLinks.forEach(function (elem) { 127 elem.addEventListener("click", addKBServicesClickEvents); 128 }); 129 //track document download 130 let documentLinks = document.querySelectorAll(`article a[href$=".pptx"], article a[href$=".docx"], article a[href$=".pdf"], article a[href$=".xlxs"]`); 131 documentLinks.forEach(function(elem){ 132 elem.addEventListener('click', function(){ 133 let fileURL = elem.getAttribute('href'); 134 documentType = fileURL.split('.').pop(), 135 documentName = fileURL.substring(fileURL.lastIndexOf('/') + 1); 136 137 let eventProperties = { 138 "document_type": documentType, 139 "location_url": ampliCurrentURL, 140 "document_name": documentName, 141 "document_url": fileURL, 142 "category": current_category 143 }; 144 145 marketing.trackEvent('Document Downloaded', eventProperties).sendToAmplitude(); // send to amplitude 146 }) 147 148 }); 149 } 150 151 //track gender free checker click 152 if(siteLang === 'de') { 153 let genderFreeButtons = document.querySelectorAll(`a[href*="scribbr.de/gendern/genderpruefung"]`); 154 genderFreeButtons.forEach(function (elem) { 155 elem.addEventListener("click", function () { 156 marketing.trackEvent('Gender Free Checker Opened').sendToAmplitude(); // send to amplitude 157 }); 158 }); 159 } 160 161 //navigation upload button clicked 162 let navOrangeButtons = document.querySelectorAll(`.btn--upload`); 163 navOrangeButtons.forEach(function (elem) { 164 elem.addEventListener("click", function () { 165 let linkURL = new URL(elem.getAttribute('href').split('?')[0], ampliCurrentURL); 166 var buttonText = elem.innerText; 167 var eventProperties = { 168 "location_url": ampliCurrentURL, 169 "location_path": window.location.pathname, 170 "destination_url": linkURL.href, 171 "destination_path": linkURL.pathname, 172 "button_text": buttonText, 173 }; 174 marketing.trackEvent('Header Button Clicked', eventProperties).sendToAmplitude(); // send to amplitude 175 }); 176 }); 177 178 //homepage click tracking 179 if (document.body.classList.contains('page-template-home-twig')) { 180 let servicesLinks = document.querySelectorAll(`.products-box-wrapper a`); 181 servicesLinks.forEach(function (elem) { 182 elem.addEventListener("click", function () { 183 var itemService; 184 if (elem.dataset.serviceName) { 185 itemService = elem.dataset.serviceName; 186 } 187 let linkURL = new URL(elem.getAttribute('href').split('?')[0]); 188 var serviceCopy = elem.innerText; 189 var eventProperties = { 190 "destination_url": linkURL.href, 191 "destination_path": linkURL.pathname, 192 "button_text": serviceCopy, 193 "service": itemService, 194 }; 195 marketing.trackEvent('Home Page Service Clicked', eventProperties).sendToAmplitude(); // send to amplitude 196 }); 197 }); 198 } 199 200 //main navigation click events 201 let navItems = document.querySelectorAll(`.main-nav .nav__list a`); 202 navItems.forEach(function (elem) { 203 elem.addEventListener("click", function () { 204 var mainItem, 205 subItem, 206 itemURL; 207 //main item or subnav 208 if (elem.classList.contains('sub-item')) { 209 subItem = elem.innerText; 210 mainItem = getParentCategory(elem.closest('li.nav-dropdown')); 211 itemURL = elem.getAttribute('href'); 212 } else { 213 subItem = ''; 214 mainItem = getParentCategory(elem.closest('li.nav-dropdown')); 215 itemURL = elem.getAttribute('href'); 216 } 217 var eventProperties = { 218 "main_item": mainItem, 219 "sub_item": subItem, 220 "destination_url": itemURL, 221 "location_url": ampliCurrentURL 222 }; 223 marketing.trackEvent('Header Clicked', eventProperties).sendToAmplitude(); // send to amplitude 224 225 }); 226 }); 227 let uploadButtons = document.querySelectorAll(`a[href*="${rootUrl}/plagiarism-checker"], a[href*="${rootUrl}/turnitin-check"], a[href*="${rootUrl}/order"]`); 228 uploadButtons.forEach(function (elem) { 229 elem.addEventListener("click", function () { 230 let uploadUrl = elem.getAttribute('href').split('?')[0], 231 buttonService = ''; 232 if(uploadUrl.includes(`${rootUrl}/plagiarism-checker`)) { 233 buttonService = 'plagiarism checker'; 234 } else if (uploadUrl.includes(`${rootUrl}/order`)) { 235 buttonService = 'proofreading & editing'; 236 } 237 let buttonText = elem.innerText, 238 buttonType = getLocationByClass(elem); 239 var eventProperties = { 240 "location_url": ampliCurrentURL, 241 'destination_url': uploadUrl, 242 "button_text": buttonText, 243 "service": buttonService, 244 "button_type": buttonType, 245 }; 246 marketing.trackEvent('Upload Button Clicked', eventProperties).sendToAmplitude(); // send to amplitude 247 }); 248 }); 249 250 // register trustpilot widget clicks
251 if (!document.body.classList.contains('knowledgebase')) { 252 window.focus(); 253 window.addEventListener("blur", () => { 254 setTimeout(() => { 255 if (document.activeElement.tagName === "IFRAME" && document.activeElement.src && document.activeElement.src.includes('trustpilot.com')) { 256 let linkURL = new URL(ampliCurrentURL); 257 let trustpilotWidgetId = document.activeElement.closest('.trustpilot-widget').getAttribute('data-template-id'); 258 var eventProperties = { 259 "url": ampliCurrentURL, 260 "path": linkURL.pathname, 261 "trustpilot_template_id": trustpilotWidgetId, 262 }; 263 marketing.trackEvent('Trustpilot Widget Clicked', eventProperties).sendToAmplitude(); // send to amplitude 264 } 265 }); 266 }, { once: false }); 267 } 268}); 269 270// Function to track External Links in Amplitude 271function trackExternalLinksInAmplitude( elem ) { 272 const href = elem.getAttribute('href'); 273 const eventProperties = { 274 external_link: href, 275 external_link_domain: new URL(href).hostname, 276 url: window.location.href, 277 }; 278 279 // Log the event to Amplitude (or handle it as needed). 280 marketing.trackEvent('External Link Clicked', eventProperties).sendToAmplitude(); 281} 282 283if (document.body.classList.contains('knowledgebase')) { 284 // Select all ad elements that have the data-service-name attribute 285 const adElements = document.querySelectorAll('[data-enable-tracking]'); // All ads with the data-service-name attribute 286 287 adElements.forEach(adElement => { 288 // Ensure the ad is in the viewport before logging the event. 289 const observer = new IntersectionObserver((entries) => { 290 entries.forEach(entry => { 291 if (entry.isIntersecting) { 292 // Get the href attribute from the ad element. 293 const adHref = adElement.href; 294 295 // Extract the 'scr_medium' query parameter from the URL. 296 const urlParams = new URLSearchParams(new URL(adHref).search); 297 const scrMedium = urlParams.get('scr_medium'); // This will get the value of 'scr_medium'. 298 299 // Track the event in Amplitude when the ad is viewed. 300 marketing.trackEvent('Ad Viewed Knowledge Base', { 301 adId: adElement.dataset.adId || 0, // Generate dynamic ad ID if not available. 302 adType: scrMedium || 'other', // Determine ad type based on class. 303 adCopy: adElement.dataset.adCopy || 'Unknown Ad Copy', // Get ad text or title for the copy. 304 service: adElement.dataset.serviceName || 'Unknown Service', // The service being promoted (from data-service-name). 305 locationUrl: window.location.href, // Current page URL 306 outgoingUrl: adElement.href || 'Unknown Outgoing URL' // The URL the ad links to. 307 }).sendToAmplitude(); 308 309 // Stop observing the ad after the event is fired to prevent repeated events. 310 observer.unobserve(entry.target); 311 } 312 }); 313 }, { threshold: 0.1 }); // Trigger when at least 10% of the ad is visible. 314 315 // Start observing the ad element. 316 observer.observe(adElement); 317 }); 318} 319 320function trackAdHoverEvent(adUnit) { 321 const url = window.location.href; 322 const path = window.location.pathname; 323 marketing.trackEvent('Why Do I See Ads Hovered', { 324 ad_unit: adUnit, 325 url: url, 326 path: path 327 }).sendToAmplitude(); 328}
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.