11export 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+
1145export 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
1549export 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+
2591export 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-
39101function isLocalhost ( script ) {
40102 const dev = script . hasAttribute ( "data-dev" ) ;
41103
0 commit comments