♻️ Refactored CloudFlare WebAnalytics partial
This commit is contained in:
parent
788762fc52
commit
d10f86937d
|
@ -23,19 +23,17 @@ about how it works and how to get the token.
|
|||
baseUrl: https://example.com/
|
||||
params:
|
||||
cloudflare:
|
||||
webAnalytics: 1d59a54b73a94728a4a9ed1b09767b1f
|
||||
webAnalytics:
|
||||
token: 1d59a54b73a94728a4a9ed1b09767b1f
|
||||
spa: true # For SPA apps/websites
|
||||
```
|
||||
|
||||
#### Template
|
||||
Inject `cloudflare/web-analytics` partial in your `<body>` (preferably as close as possible to the closing tag):
|
||||
|
||||
```html
|
||||
<head>
|
||||
{{ partialCached "cloudflare/web-analytics/head" . $.Site.Language.Lang }}
|
||||
</head>
|
||||
...
|
||||
<body>
|
||||
...
|
||||
{{ partialCached "cloudflare/web-analytics/body" . $.Site.Language.Lang }}
|
||||
{{ partialCached "cloudflare/web-analytics" . }}
|
||||
</body>
|
||||
```
|
|
@ -1 +1,12 @@
|
|||
{{ partialCached "web-analytics/body" . }}
|
||||
{{ with $.Site.Params.cloudflare.webAnalytics }}
|
||||
{{- $spa := false -}}
|
||||
{{- if .spa -}}
|
||||
{{- $spa = .spa -}}
|
||||
{{- end -}}
|
||||
{{- $payload := dict
|
||||
"token" .token
|
||||
"spa" $spa
|
||||
| jsonify -}}
|
||||
<script src="https://static.cloudflareinsights.com/beacon.min.js"
|
||||
{{ printf `data-cf-beacon='%s'` $payload | safeHTMLAttr }} defer></script>
|
||||
{{ end }}
|
|
@ -1,3 +0,0 @@
|
|||
{{ with $.Site.Params.cloudflare.webAnalytics }}
|
||||
<script src="https://static.cloudflareinsights.com/beacon.min.js" data-cf-beacon="{'token':'{{ . | safeJS }}'}" defer></script>
|
||||
{{ end }}
|
|
@ -1,4 +0,0 @@
|
|||
{{ with $.Site.Params.cloudflare.webAnalytics }}
|
||||
<link rel="preconnect" href="https://static.cloudflareinsights.com" crossorigin="anonymous">
|
||||
<link rel="preload" as="script" href="https://static.cloudflareinsights.com/beacon.min.js" type="text/javascript" crossorigin="anonymous">
|
||||
{{ end }}
|
Loading…
Reference in New Issue