Bladeren bron

Add ?utm_source=indieweb to outgoing links

Per this toot from Mastodon user Ben Werdmuller, adding this tag that's
used by many analytics softwares to track referals like which social
media brought a user in can help promote the concept of the IndieWeb by
showing that a fair amount of traffic is coming from there.

https://werd.social/@ben/109485020875462153
Apis Necros 2 jaren geleden
bovenliggende
commit
fed963f138
1 gewijzigde bestanden met toevoegingen van 7 en 1 verwijderingen
  1. 7 1
      layouts/_default/_markup/render-link.html

+ 7 - 1
layouts/_default/_markup/render-link.html

@@ -1,6 +1,12 @@
 {{- $sameSite := true -}}
+{{- $finalDest := .Destination -}}
 {{- if eq (.Destination | relURL) (.Destination | absURL) }}{{ $sameSite = false }}{{ end -}}
-<a href="{{ .Destination }}"
+{{- if not $sameSite -}}
+    {{- if in $finalDest "?"}}{{ $finalDest = printf "%s%s" $finalDest "&utm_source=indieweb" -}}
+    {{- else }}{{ $finalDest = printf "%s%s" $finalDest "?utm_source=indieweb" -}}
+    {{- end -}}
+{{- end -}}
+<a href="{{ $finalDest }}"
     {{- if not $sameSite }} target="_blank"
         {{- with .Title }} rel="{{ . | safeHTML }}"{{ end }}
     {{- else }} rel="me"{{ end }}>{{.Text | safeHTML}}</a>