forked from AllanTracker/codigos-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutm_term (doppus)
55 lines (49 loc) · 1.73 KB
/
utm_term (doppus)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<script>
let prefix = ["https://go.pianoem21dias.com/checkout"];
function getParams() {
let t = "",
e = window.top.location.href,
r = new URL(e);
if (null != r) {
let a = r.searchParams.get("utm_source"),
n = r.searchParams.get("utm_medium"),
o = r.searchParams.get("utm_campaign"),
p = r.searchParams.get("fbclid"),
c = r.searchParams.get("utm_content");
-1 !== e.indexOf("?") && (t = `&sck=${a}|${n}|${o}|${c}`);
console.log(t);
}
return t;
}
function getCookie(name) {
let match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
if (match) {
return match[2];
}
return null;
}
function updateLinks() {
var t = new URLSearchParams(window.location.search);
var xcod = getCookie("Leadsf");
if (xcod) {
t.append("utm_term", xcod);
t.toString() && document.querySelectorAll("a").forEach(function(e) {
for (let r = 0; r < prefix.length; r++) {
if (-1 !== e.href.indexOf(prefix[r])) {
if (-1 === e.href.indexOf("?")) {
e.href += "?" + t.toString() + getParams();
} else {
e.href += "&" + t.toString() + getParams();
}
}
}
});
} else {
// Tenta novamente após 100ms se o cookie ainda não estiver presente
setTimeout(updateLinks, 100);
}
}
window.addEventListener('load', function() {
updateLinks();
});
</script>