Skip to content

Commit

Permalink
use partytown to offload gtag
Browse files Browse the repository at this point in the history
  • Loading branch information
remvn committed Sep 23, 2024
1 parent 1c143eb commit fe6d6ca
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 62 deletions.
4 changes: 0 additions & 4 deletions config/_default/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ enableRobotsTXT: true
paginate: 10
summaryLength: 0

services:
googleAnalytics:
ID: G-D3VB7YFCTH

outputs:
home:
- HTML
Expand Down
11 changes: 11 additions & 0 deletions config/_default/module.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
imports:
- path: github.com/jpanther/congo/v2
- path: github.com/remvn/hugo-vmoji

mounts:
- source: assets
target: assets
- source: node_modules/@builder.io/partytown/lib/partytown.js
target: assets/js/partytown.js
- source: static
target: static
- source: node_modules/@builder.io/partytown/lib
target: static/~partytown
excludeFiles: debug
2 changes: 2 additions & 0 deletions config/_default/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ enableImageLazyLoading: true
enableImageWebp: true
fingerprintAlgorithm: sha256

gtmID: "G-D3VB7YFCTH"

images:
- images/gopher-feature.jpg
- images/avatar-cover.jpg
Expand Down
25 changes: 25 additions & 0 deletions layouts/partials/analytics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- Partytown Setup -->
<script type="text/javascript">
partytown = {
forward: ["dataLayer.push"],
};
</script>
<script type="text/javascript">
{{ $partytownJs := resources.Get "js/partytown.js" | js.Build | minify }}
{{- $partytownJs.Content | safeJS }}
</script>
<!-- End Partytown -->

<!-- Google tag (gtag.js) -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-D3VB7YFCTH"
></script>

<script type="text/partytown">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', "{{ .Site.Params.gtmID }}");
</script>
119 changes: 66 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions package.hugo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "hugo-blog",
"version": "1.0.0",
"license": "ISC",
"devDependencies": {
"@builder.io/partytown": "^0.10.2",
"prettier": "^3.3.3",
"prettier-plugin-go-template": "^0.0.15"
}
}
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
{
"name": "blog",
"version": "1.0.0",
"license": "ISC",
"comments": {
"dependencies": {},
"devDependencies": {
"prettier": "^3.3.3",
"prettier-plugin-go-template": "^0.0.15"
"@builder.io/partytown": "project",
"prettier": "project",
"prettier-plugin-go-template": "project"
}
},
"dependencies": {},
"devDependencies": {
"@builder.io/partytown": "^0.10.2",
"prettier": "^3.3.3",
"prettier-plugin-go-template": "^0.0.15"
},
"license": "ISC",
"name": "hugo-blog",
"version": "1.0.0"
}

0 comments on commit fe6d6ca

Please sign in to comment.