Skip to content

Commit 9a8888a

Browse files
committed
Added pa.js, removed DNT, updated dependencies.
1 parent af04c0e commit 9a8888a

15 files changed

Lines changed: 1835 additions & 340 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
vendor/
22
node_modules/
33
pirsch/
4+
pa.min.js
45
pirsch.min.js
56
pirsch-events.min.js
67
pirsch-sessions.min.js

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## Changelog
22

3+
## 1.7.0
4+
5+
* added pa.js
6+
* removed DNT
7+
* updated dependencies
8+
39
## 1.6.0
410

511
* added support for client hints

build_release.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ cp index.php pirsch
2222
cp pirsch-sessions.min.js pirsch
2323
cp pirsch-events.min.js pirsch
2424
cp pirsch.min.js pirsch
25+
cp pa.min.js pirsch
2526
cp proxy.php pirsch
2627

2728
zip -r "pirsch_proxy_v$1.zip" pirsch

common.js

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,49 @@
11
export function getScript(id) {
22
const script = document.querySelector(id);
33

4-
if(!script) {
4+
if (!script) {
55
throw `Pirsch script ${id} tag not found!`;
66
}
77

88
return script;
99
}
1010

11+
export function getPathOrTitleSuffixOrPrefix(list, index) {
12+
let entry = "";
13+
14+
if (list.length > 0) {
15+
if (index < list.length) {
16+
entry = list[index];
17+
} else {
18+
entry = list[list.length-1];
19+
}
20+
}
21+
22+
return entry;
23+
}
24+
25+
export function getTags(script) {
26+
const tags = {};
27+
28+
for (const attribute of script.attributes) {
29+
if (attribute.name.startsWith("data-tag-")) {
30+
tags[attribute.name.substring("data-tag-".length).replaceAll("-", " ")] = attribute.value || "1";
31+
} else if (attribute.name.startsWith("data-tag") && attribute.value) {
32+
attribute.value.split(",").forEach(t => {
33+
t = t.trim().replaceAll("-", " ");
34+
35+
if (t) {
36+
tags[t] = "1";
37+
}
38+
});
39+
}
40+
}
41+
42+
return tags;
43+
}
44+
1145
export function ignore(script) {
12-
return dnt() || isLocalhost(script) || !includePage(script) || excludePage(script);
46+
return localStorage.getItem("disable_pirsch") || isLocalhost(script) || !includePage(script) || excludePage(script);
1347
}
1448

1549
export function rewriteHostname(hostname) {
@@ -22,6 +56,38 @@ export function rewriteHostname(hostname) {
2256
return hostname;
2357
}
2458

59+
export function rewritePath(url, prefix, suffix) {
60+
if (!url) {
61+
url = location.href;
62+
}
63+
64+
if (!prefix) {
65+
prefix = "";
66+
}
67+
68+
if (!suffix) {
69+
suffix = "";
70+
}
71+
72+
const u = new URL(url);
73+
u.pathname = prefix+u.pathname+suffix;
74+
return u.toString();
75+
}
76+
77+
export function rewriteTitle(prefix, suffix) {
78+
let title = document.title;
79+
80+
if (!prefix) {
81+
prefix = "";
82+
}
83+
84+
if (!suffix) {
85+
suffix = "";
86+
}
87+
88+
return prefix+title+suffix;
89+
}
90+
2591
export function rewriteReferrer(hostname) {
2692
let referrer = document.referrer;
2793

@@ -32,10 +98,6 @@ export function rewriteReferrer(hostname) {
3298
return referrer;
3399
}
34100

35-
function dnt() {
36-
return navigator.doNotTrack === "1" || localStorage.getItem("disable_pirsch");
37-
}
38-
39101
function isLocalhost(script) {
40102
const dev = script.hasAttribute("data-dev");
41103

0 commit comments

Comments
 (0)