-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinkTagging.html
35 lines (33 loc) · 2.47 KB
/
LinkTagging.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<script>
for (i = 0; i < document.getElementsByTagName("A").length; i++) {
//Link Type detection and attribution to data-clic-type
if(document.getElementsByTagName("A")[i].getAttribute("href") == null){
}else if(document.getElementsByTagName("A")[i].getAttribute("href").startsWith('htt') && !(document.getElementsByTagName("A")[i].getAttribute("href").includes(".internet.com"))){
typeClicked = 'exit'
}else if(document.getElementsByTagName("A")[i].getAttribute("href").includes("#nav-")){
typeClicked = 'navigation'
}else if((document.getElementsByTagName("A")[i].getAttribute("href").includes(".pdf"))||(document.getElementsByTagName("A")[i].getAttribute("href").includes(".xls"))){
typeClicked = 'download'
}else if(document.getElementsByTagName("A")[i].getAttribute("href").includes('#go-')){
typeClicked = 'action'
}else{typeClicked = 'navigation'}
document.getElementsByTagName("A")[i].setAttribute('data-click-type', typeClicked);
//Link position detection and attribution to data-click-position
document.getElementsByTagName('A')[i].setAttribute('data-click-position',i+1);
//Link text detection, concatenation with page name and attribution to data-click-name
if(chapterA == "" && chapterB == "" && chapterC ==""){
document.getElementsByTagName("A")[i].setAttribute('data-click-name',page +'-'+document.getElementsByTagName('a')[i].text);
}else if(chapterA == undefined && chapterB == undefined && chapterC == undefined){
document.getElementsByTagName("A")[i].setAttribute('data-click-name',page +'-'+document.getElementsByTagName('a')[i].text);
}else if(chapterA !="" && chapterB =="" && chapterC ==""){
document.getElementsByTagName("A")[i].setAttribute('data-click-name', chapterA+'::'+page+'-'+document.getElementsByTagName('a')[i].text);
}else if(chapterA !="" && chapterB !="" && chapterC ==""){
document.getElementsByTagName("A")[i].setAttribute('data-click-name', chapterA+'::'+chapterB+'::'+page+'-'+document.getElementsByTagName('a')[i].text);
}else if(chapterA !="" && chapterB !="" && chapterC !=""){
document.getElementsByTagName("A")[i].setAttribute('data-click-name', chapterA+'::'+chapterB+'::'+chapterC+'::'+page+'-'+document.getElementsByTagName('a')[i].text);
}
//Level 2 site of the current page attribution to data-click-s2
var s2Click = s2;
document.getElementsByTagName("A")[i].setAttribute('data-click-s2', s2Click);
}
</script>