Skip to content

Commit 957de0f

Browse files
authored
Update external_tracking.md (#161)
Umami Analytics tracking setup.
1 parent a454e3e commit 957de0f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs/external_tracking.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,38 @@ navigation.addEventListener("navigate", function (e) {
8585
trackPageView()
8686
});
8787
```
88+
## Set up for Umami Analytics
89+
90+
> ⚠️ Make sure to use your actual values for DOMAIN SCRIPT URL and <WEBSITE_ID>
91+
92+
### Allow loading tracking script
93+
94+
Set the following env vars:
95+
96+
```ini
97+
SECURITY_HEADER_SCRIPT_SRC_ALLOW=https://umami.example.com/script.js
98+
SECURITY_HEADER_CSP_CONNECT_SRC=https://umami.example.com/script.js
99+
```
100+
101+
### Add custom JavaScript
102+
103+
Add the following to Settings > Custom JS
104+
105+
```javascript
106+
(function() {
107+
var d = document, s = d.createElement('script'), g = d.getElementsByTagName('script')[0];
108+
s.defer = true;
109+
s.src = 'https://umami.example.com/script.js';
110+
s.setAttribute('data-website-id', '<WEBSITE_ID>');
111+
g.parentNode.insertBefore(s, g);
112+
})();
113+
114+
navigation.addEventListener("navigate", function (e) {
115+
if (window.umami && typeof umami.trackView === 'function') {
116+
umami.trackView(document.title, window.location.pathname);
117+
}
118+
});
119+
```
88120

89121
## Other tools / custom tracking
90122

0 commit comments

Comments
 (0)