mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-13 16:14:05 +00:00
feat: port analytics to blox-analytics
This commit is contained in:
1 parent
824ef0dbf0
commit
1bc54d5d14
13 files changed
+71
No files matched your search
@@ -0,0 +1,27 @@
|
||||
# blox-analytics
|
||||
|
||||
**A Hugo module (plugin) for website analytics and search engine verification.**
|
||||
|
||||
Are you using the `blox-tailwind` module? The analytics module is already included, so you do not need to install it. For all other sites, refer to the installation guide below.
|
||||
|
||||
## Install
|
||||
|
||||
Get analytics and verification for your Hugo site by following the guide below:
|
||||
|
||||
1. Add the module to your `config/_default/hugo.yaml`:
|
||||
|
||||
```yaml
|
||||
module:
|
||||
imports:
|
||||
- path: github.com/HugoBlox/hugo-blox-builder/modules/blox-analytics
|
||||
```
|
||||
|
||||
2. Load the module in your site's `<head>` with:
|
||||
|
||||
```go
|
||||
{{ partial "blox_analytics/index" . }}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
[View the documentation](https://docs.hugoblox.com/reference/analytics/)
|
||||
@@ -0,0 +1,3 @@
|
||||
module github.com/HugoBlox/hugo-blox-builder/modules/blox-analytics
|
||||
|
||||
go 1.15
|
||||
@@ -0,0 +1,4 @@
|
||||
module:
|
||||
mounts:
|
||||
- source: layouts
|
||||
target: layouts
|
||||
@@ -0,0 +1,9 @@
|
||||
{{/* HUGO BLOX: MARKETING MODULE */}}
|
||||
|
||||
{{/* VERIFICATIONS */}}
|
||||
|
||||
{{ partial "blox-analytics/verification" . }}
|
||||
|
||||
{{/* ANALYTICS */}}
|
||||
|
||||
{{ partial "blox-analytics/services/index" . }}
|
||||
@@ -0,0 +1,13 @@
|
||||
{{ $baidu_tongji := site.Params.marketing.analytics.baidu_tongji | default "" }}
|
||||
|
||||
{{ if hugo.IsProduction | and $baidu_tongji }}
|
||||
<script>
|
||||
var _hmt = _hmt || [];
|
||||
(function() {
|
||||
var hm = document.createElement("script");
|
||||
hm.src = "https://hm.baidu.com/hm.js?{{ $baidu_tongji }}";
|
||||
var s = document.getElementsByTagName("script")[0];
|
||||
s.parentNode.insertBefore(hm, s);
|
||||
})();
|
||||
</script>
|
||||
{{ end }}
|
||||
@@ -0,0 +1,5 @@
|
||||
{{ $fathom := site.Params.marketing.analytics.fathom | default "" }}
|
||||
|
||||
{{ if hugo.IsProduction | and $fathom }}
|
||||
<script src="https://cdn.usefathom.com/script.js" data-site="{{$fathom}}" defer></script>
|
||||
{{ end }}
|
||||
@@ -0,0 +1,42 @@
|
||||
{{ $ga := site.Params.marketing.analytics.google_analytics | default site.GoogleAnalytics | default "" }}
|
||||
|
||||
{{ if hugo.IsProduction | and $ga }}
|
||||
|
||||
{{ $gtag_config := cond site.Params.features.privacy_pack.enable "{ 'anonymize_ip': true }" "{}" }}
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id={{$ga}}"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
|
||||
function gtag() {
|
||||
dataLayer.push(arguments);
|
||||
}
|
||||
|
||||
function trackOutboundLink(url, target) {
|
||||
gtag('event', 'click', {
|
||||
'event_category': 'outbound',
|
||||
'event_label': url,
|
||||
'transport_type': 'beacon',
|
||||
'event_callback': function () {
|
||||
if (target !== '_blank') {
|
||||
document.location = url;
|
||||
}
|
||||
}
|
||||
});
|
||||
console.debug("Outbound link clicked: " + url);
|
||||
}
|
||||
|
||||
function onClickCallback(event) {
|
||||
if ((event.target.tagName !== 'A') || (event.target.host === window.location.host)) {
|
||||
return;
|
||||
}
|
||||
trackOutboundLink(event.target, event.target.getAttribute('target')); // Send GA event.
|
||||
}
|
||||
|
||||
gtag('js', new Date());
|
||||
gtag('config', '{{$ga}}', {{$gtag_config|safeJS}});
|
||||
gtag('set', {'cookie_flags': 'SameSite=None;Secure'});
|
||||
|
||||
// Outbound link tracking.
|
||||
document.addEventListener('click', onClickCallback, false);
|
||||
</script>
|
||||
{{ end }}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{{ $gt := site.Params.marketing.analytics.google_tag_manager | default "" }}
|
||||
{{ if hugo.IsProduction | and $gt }}
|
||||
<script>
|
||||
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
||||
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
||||
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
||||
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
||||
})(window,document,'script','dataLayer','{{$gt}}');
|
||||
</script>
|
||||
{{ end }}
|
||||
@@ -0,0 +1,7 @@
|
||||
{{ partial "blox-analytics/services/google_analytics" . }}
|
||||
{{ partial "blox-analytics/services/google_tag_manager" . }}
|
||||
{{ partial "blox-analytics/services/microsoft_clarity" . }}
|
||||
{{ partial "blox-analytics/services/baidu_tongji" . }}
|
||||
{{ partial "blox-analytics/services/plausible" . }}
|
||||
{{ partial "blox-analytics/services/fathom" . }}
|
||||
{{ partial "blox-analytics/services/pirsch" . }}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{{ $clarity := site.Params.marketing.analytics.microsoft_clarity | default "" }}
|
||||
{{ if hugo.IsProduction | and $clarity }}
|
||||
<script>
|
||||
(function(c,l,a,r,i,t,y){
|
||||
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
|
||||
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
|
||||
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
|
||||
})(window, document, "clarity", "script", '{{$clarity}}');
|
||||
</script>
|
||||
{{ end }}
|
||||
@@ -0,0 +1,5 @@
|
||||
{{ $pirsch := site.Params.marketing.analytics.pirsch | default "" }}
|
||||
|
||||
{{ if hugo.IsProduction | and $pirsch }}
|
||||
<script defer src="https://api.pirsch.io/pirsch.js" id="pirschjs" data-code="{{$pirsch}}"></script>
|
||||
{{ end }}
|
||||
@@ -0,0 +1,5 @@
|
||||
{{ $plausible := site.Params.marketing.analytics.plausible | default "" }}
|
||||
|
||||
{{ if hugo.IsProduction | and $plausible }}
|
||||
<script defer data-domain="{{$plausible}}" src="https://plausible.io/js/script.js"></script>
|
||||
{{ end }}
|
||||
@@ -0,0 +1,21 @@
|
||||
{{/* Site Verification with Third Party Services */}}
|
||||
|
||||
{{- with site.Params.marketing.verification.google -}}
|
||||
<meta name="google-site-verification" content="{{ . }}" />
|
||||
{{- end -}}
|
||||
|
||||
{{- with site.Params.marketing.verification.bing -}}
|
||||
<meta name="msvalidate.01" content="{{ . }}" />
|
||||
{{- end -}}
|
||||
|
||||
{{- with site.Params.marketing.verification.yandex -}}
|
||||
<meta name="yandex-verification" content="{{ . }}" />
|
||||
{{- end -}}
|
||||
|
||||
{{- with site.Params.marketing.verification.pinterest -}}
|
||||
<meta name="p:domain_verify" content="{{ . }}" />
|
||||
{{- end -}}
|
||||
|
||||
{{- with site.Params.marketing.verification.baidu -}}
|
||||
<meta name="baidu-site-verification" content="{{ . }}" />
|
||||
{{- end -}}
|
||||
Reference in new issue
Block a user