Skip to content

Commit 2d7a301

Browse files
authored
Add a tracking pixel with JavaScript (jenkinsci#1800)
* Add a tracking pixel with JavaScript * Remove prior attempt at tracking pixel
1 parent e9b9370 commit 2d7a301

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

README.adoc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
:toc: macro
44
:toc-title:
55

6+
+++
7+
<script src="images/scarf.js"></script>
8+
+++
9+
610
[#introduction]
711
== Introduction
812

913
image::images/jenkins-and-git.png[Jenkins and Git]
10-
image::https://static.scarf.sh/a.png?x-pxid=e010adc8-3614-41ef-b7e8-2f42328e8962&page=git-plugin-readme[]
1114

1215
The git plugin provides fundamental git operations for Jenkins projects.
1316
It can poll, fetch, checkout, branch, list, merge, tag, and push repositories.

images/scarf.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(function () {
2+
const pixelID = 'e011adc8-3614-41ef-b7e8-2f42328e8962';
3+
let lastHref = null;
4+
5+
function sendScarfPing() {
6+
const currentHref = window.location.href;
7+
if (currentHref === lastHref) return;
8+
lastHref = currentHref;
9+
10+
const url = `https://static.scarf.sh/a.png?x-pxid=${pixelID}`;
11+
const img = new Image();
12+
img.referrerPolicy = 'no-referrer-when-downgrade';
13+
img.src = url;
14+
}
15+
16+
['pushState', 'replaceState'].forEach(fn => {
17+
const original = history[fn];
18+
history[fn] = function () {
19+
original.apply(this, arguments);
20+
window.dispatchEvent(new Event('scarf:locationchange'));
21+
};
22+
});
23+
24+
window.addEventListener('hashchange', sendScarfPing);
25+
window.addEventListener('popstate', sendScarfPing);
26+
window.addEventListener('scarf:locationchange', sendScarfPing);
27+
28+
sendScarfPing(); // initial page load
29+
})();

0 commit comments

Comments
 (0)