Analytics tries to identify exactly which elements on the page users clicked. If an element has a unique ID, then Analytics is able to identify the number of clicks on that element. If an element does not have a unique ID, then Analytics looks up to three levels higher in the DOM structure for a unique ID (i.e., the element's parent's parent). If Analytics is still unable to find a unique ID, then you see a range.
Created
October 27, 2016 22:26
-
-
Save r-k-b/04cc49faecf808b858f390853b88cdad to your computer and use it in GitHub Desktop.
How many links on the page will work with Enhanced Link Attribution in Google Analytics?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
function hasId(elem) { | |
return !!elem.id && elem.id.length > 0 | |
} | |
function ancestorsHaveNoId(elem) { | |
return !(hasId(elem) || hasId(elem.parentNode) || hasId(elem.parentNode.parentNode)) | |
} | |
let links = [].slice.call(document.querySelectorAll('a')); | |
let fails = links.filter(ancestorsHaveNoId); | |
console.info('# of links:', links.length); | |
console.info('# of failed links:', fails.length); | |
console.log(fails); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment