mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-13 15:04:50 -04:00
GA track outgoing sponsor clikcs
This commit is contained in:
parent
aca59ac661
commit
cf8a937280
@ -9,7 +9,7 @@
|
||||
{{- partial "home-page-sections/features-icons" . -}}
|
||||
</section>
|
||||
|
||||
{{ partial "home-page-sections/sponsors.html" (dict "cx" . ) }}
|
||||
{{ partial "home-page-sections/sponsors.html" (dict "cx" . "gtag" "home" ) }}
|
||||
|
||||
{{- partial "home-page-sections/features-single" . -}}
|
||||
|
||||
|
@ -6,5 +6,21 @@
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', '{{ . }}');
|
||||
|
||||
/**
|
||||
* Function that tracks a click on an outbound link in Analytics.
|
||||
* Setting the transport method to 'beacon' lets the hit be sent
|
||||
* using 'navigator.sendBeacon' in browser that support it.
|
||||
*/
|
||||
var trackOutboundLink = function(id, url) {
|
||||
console.log("track:", id, url)
|
||||
gtag('event', 'click', {
|
||||
'event_category': 'outbound',
|
||||
'event_label': id,
|
||||
'transport_type': 'beacon',
|
||||
'event_callback': function(){document.location = url;}
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
{{ end }}
|
@ -1,14 +1,22 @@
|
||||
{{$classes_box := "ba b--light-gray bg-light-gray br3 flex flex-column flex-wrap items-center justify-center ph3 pv4 mb4 w-100 w-30-l "}}
|
||||
{{$gtag := .gtag | default "unknown" }}
|
||||
{{ with .cx.Site.Data.sponsors }}
|
||||
<section class="{{ $.classes_section | default "bg-primary-color-dark b--dark-gray bb bt ph5 pv4 w-100"}}">
|
||||
<div class="center mw9">
|
||||
<f3 class="b f3 light-gray">Hugo Sponsors</f3>
|
||||
<div class="flex-ns flex-wrap center justify-between pt3">
|
||||
{{ range .banners }}
|
||||
{{ $banner := . }}
|
||||
{{if .logo}}
|
||||
<div class="{{$classes_box}} o-100">
|
||||
{{with .link -}}
|
||||
<a href="{{.}}?{{ (querify "utm_source" "homepage" "utm_medium" "banner" "utm_campaign" "hugosponsor") | safeURL }}" class="grow">
|
||||
{{ $url := printf "%s?%s" . (querify "utm_source" "homepage" "utm_medium" "banner" "utm_campaign" "hugosponsor") | safeURL }}
|
||||
{{ if eq (getenv "HUGO_ENV") "production" | or (eq $.cx.Site.Params.env "production") }}
|
||||
{{ $gtagID := printf "Sponsor %s %s" $banner.name $gtag | title }}
|
||||
<a href="{{ $url }}" onclick="trackOutboundLink({{ printf "'%s', '%s'" $gtagID $url | safeJS }}); return false;" class="grow">
|
||||
{{ else }}
|
||||
<a href="{{ $url }}" class="grow">
|
||||
{{ end }}
|
||||
{{- end}}
|
||||
<img src="{{ .logo }}" alt="Logo for {{ .name }}" class="img h3 center" />
|
||||
{{with .link}}</a>{{end}}
|
||||
|
@ -29,7 +29,7 @@
|
||||
</div>
|
||||
|
||||
<div class="w-100 w-50-l">
|
||||
{{ partial "home-page-sections/sponsors.html" (dict "cx" . "classes_section" "pb3 w-100" "classes_copy" "f7 w-90-ns") }}
|
||||
{{ partial "home-page-sections/sponsors.html" (dict "cx" . "gtag" "footer" "classes_section" "pb3 w-100" "classes_copy" "f7 w-90-ns") }}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user