Skip to content

Instantly share code, notes, and snippets.

@damien1
Last active July 14, 2020 21:34
Show Gist options
  • Save damien1/eb8c580cbfb8c0222e8da03375fb54aa to your computer and use it in GitHub Desktop.
Save damien1/eb8c580cbfb8c0222e8da03375fb54aa to your computer and use it in GitHub Desktop.
Google Analytics Event Tracking Shortcode for Hugo go to https://damien.co https://bit.ly/2CaakSY for details example to use {{< ga-tag href="https://damien.co/blog" ga1=Outbound ga2=Gist ga3=demo text="click me" >}}
<!-- for details on usage vist my site https://bit.ly/2CaakSY -->
{{ $url := .Get "href" }}
{{ $ga1 := .Get "ga1" }}
{{ $ga2 := .Get "ga2" }}
{{ $ga3 := .Get "ga3" }}
{{ $text := .Get "text" }}
<!-- use this for analytics.js -->
<!-- <a onclick="ga('send', 'event', '{{ $ga1 }}', '{{ $ga2 }}', '{{ $ga3 }}');" href="{{ $url }}" target="_blank">{{ $text }}</a> -->
<!-- use this with gtag newer tracking code -->
<a onclick="gtag('event', '{{ $ga1 }}', {'event_category': '{{ $ga2 }}', 'event_label': '{{ $ga3 }}'});" href="{{ $url }}" target="_blank">{{ $text }}</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment