Support for google Analytics conversions tests (UTM parameters)


While I know that Hugo can integrate standard Google Analytics Property IDs (such as UA-XXXX), my question is, whether hugo also supports passing the UTM parameters for conversion goal tracking ( )

Best regards,


1 Like

It would be a must have feature. I like the idea. It might be implemented so as to add the utm parameters to all anchored-link-URLs in pages. Maybe it could be achieved by allowing the user to define utm parameters in config file.

config.toml (prototype):

source = "Campaign Source"
medium = "Campaign Medium"
name = "Campaign Name"
term = "Campaign Term" # Optional
content = "Campaign Content" # Optional


@davidsneighbour @zwbetz @pointyfar What do you think about this feature? :thinking:

Sincere apologies for bumping this post. I think it is a good feature, that community might benefit from.

I am pretty sure this could be done with a “Markdown Render Hook”, introduced in 0.62.

I’ll have a look into it tonight. I would be against putting this feature into Hugo, because next to Google Analytics there are plenty of other providers with their own tags. Better would be something like a filter that takes all links and adds the terms you need. I don’t know though, how powerful these render hooks are… will get back to you about that.

It turns out they do something completely different than I thought :wink:

So, what I would do to achieve these tracked links would be some kind of shortcode that renders the proper link. Something like {{< trackedlink url="" param2="bla" >}}something{{< / trackedlink >}} and in your config.toml in the params section you configure the parameters like

param1 = value1
param2 = value2

and out comes

<a href="">something</a>

I have a shortcode somewhere that creates links for me. I’ll look if I can rewrite that one.

This method will have -one- two problems:

  1. you have to add it per link and it does not just exchange all links. on the other side - you probably won’t have to track every single link.
  2. I am not sure yet how to handle the possibility that the link already has parameters. it might need an additional parameter that forces a start with & if the link in url already has a ?.

Thanks for the input! And, yep, it’s possible!

I just tried to understand RenderHooks, and if I am not mistaken,
an example of layouts/_default/_markup/render-link.html could be:

utmSource: "website-name"
utmMedium: "website"
utmCampaign: "blog-post-title"
<a href="
{{- if in .Destination "?utm" }}
  {{- .Destination | safeURL }}
{{- else }}
  {{- .Destination | safeURL }}?utm_source=website-name&utm_medium=website&utm_campaign=blog-post-title
{{- end -}}
{{- with .Title }} title="{{ . }}" {{- end }}
{{- if strings.HasPrefix .Destination "http" }} target="_blank" {{- end -}} > {{- .Text -}} </a>

Links present in frontmatter variables, if any, would not be affected though. Such variables would need to be called with markdownify. Example, {{ .Params.variable | markdownify }}. It may have unwanted side-effects though.