Skip to content

Commit b63b65c

Browse files
committed
Updated scripts.
1 parent 490be81 commit b63b65c

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

CHANGELOG.md

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

3+
## 1.3.0
4+
5+
* updated scripts
6+
37
## 1.2.0
48

59
* events are now send asynchronously, so it’s no longer required to wait for the request to go through before switching the page

pirsch-events.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747

4848
// register event function
4949
const endpoint = script.getAttribute("data-endpoint") || "/pirsch/event";
50+
const disableQueryParams = script.hasAttribute("data-disable-query");
51+
const disableReferrer = script.hasAttribute("data-disable-referrer");
52+
const disableResolution = script.hasAttribute("data-disable-resolution");
53+
5054
window.pirsch = function (name, options) {
5155
if (typeof name !== "string" || !name) {
5256
return Promise.reject("The event name for Pirsch is invalid (must be a non-empty string)! Usage: pirsch('event name', {duration: 42, meta: {key: 'value'}})");
@@ -62,11 +66,11 @@
6266
}
6367

6468
if (navigator.sendBeacon(endpoint, JSON.stringify({
65-
url: location.href.substring(0, 1800),
69+
url: disableQueryParams ? (location.href.includes('?') ? location.href.split('?')[0] : location.href).substring(0, 1800) : location.href.substring(0, 1800),
6670
title: document.title,
67-
referrer: document.referrer,
68-
screen_width: screen.width,
69-
screen_height: screen.height,
71+
referrer: (disableReferrer ? '' : document.referrer),
72+
screen_width: (disableResolution ? 0 : screen.width),
73+
screen_height: (disableResolution ? 0 : screen.height),
7074
event_name: name,
7175
event_duration: options && options.duration && typeof options.duration === "number" ? options.duration : 0,
7276
event_meta: meta

pirsch.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,18 @@
4747

4848
// register hit function
4949
const endpoint = script.getAttribute("data-endpoint") || "/pirsch/hit";
50+
const disableQueryParams = script.hasAttribute("data-disable-query");
51+
const disableReferrer = script.hasAttribute("data-disable-referrer");
52+
const disableResolution = script.hasAttribute("data-disable-resolution");
5053

5154
function hit() {
5255
const url = endpoint +
5356
"?nc=" + new Date().getTime() +
54-
"&url=" + encodeURIComponent(location.href.substring(0, 1800)) +
57+
"&url=" + encodeURIComponent(disableQueryParams ? (location.href.includes('?') ? location.href.split('?')[0] : location.href).substring(0, 1800) : location.href.substring(0, 1800)) +
5558
"&t=" + encodeURIComponent(document.title) +
56-
"&ref=" + encodeURIComponent(document.referrer) +
57-
"&w=" + screen.width +
58-
"&h=" + screen.height;
59+
"&ref=" + (disableReferrer ? '' : encodeURIComponent(document.referrer)) +
60+
"&w=" + (disableResolution ? '' : screen.width) +
61+
"&h=" + (disableResolution ? '' : screen.height);
5962
const req = new XMLHttpRequest();
6063
req.open("GET", url);
6164
req.send();

0 commit comments

Comments
 (0)