Skip to content

Commit 6837dfd

Browse files
committed
Add a script to inject UTM parameters
1 parent 8d702f7 commit 6837dfd

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<%# Add UTM parameters to `<a>` links.
2+
3+
# Notes:
4+
- `utm_medium=partnership` is added to Sketchy links.
5+
- `utm_source=ankihub` is added to other links.
6+
7+
_%>
8+
9+
<script>
10+
for(const anchor of document.querySelectorAll("a")) {
11+
try {
12+
const url = new URL(anchor.href);
13+
if (!url.protocol.startsWith("http")) {
14+
continue;
15+
}
16+
const params = new Map();
17+
if (url.hostname.endsWith("sketchy.com")) {
18+
params.set("utm_medium", "partnership");
19+
} else {
20+
params.set("utm_source", "ankihub");
21+
}
22+
for(const [key, value] of params.entries()) {
23+
if(!url.searchParams.get(key)) {
24+
url.searchParams.set(key, value);
25+
}
26+
}
27+
anchor.href = url.toString();
28+
} catch {
29+
30+
}
31+
}
32+
</script>

src/notetypes/AnKingOverhaul/back.ejs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,5 @@ replace the arrows/dashes from the statement below with double curly brackets-->
168168
<%- include('src/components/imageBlur.ejs') %>
169169

170170
<%- include('src/components/shuffleItems.ejs') %>
171+
172+
<%- include('src/components/addUtmParameters.ejs') %>

src/notetypes/AnKingOverhaul/front.ejs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ var autoflip = false
4646
qFade=0; if (typeof anki !== 'undefined') anki.qFade=qFade;
4747
</script>
4848

49-
<%- include('src/components/colorfulTags.ejs') %>
49+
<%- include('src/components/colorfulTags.ejs') %>
50+
51+
<%- include('src/components/addUtmParameters.ejs') %>

0 commit comments

Comments
 (0)