おこなうこと

Quartz4 では Google Analytics などのトラッキングツールを利用できます。 今回は Google Analytics の設定を Public リポジトリの Quartz4 に対して設定します。

url: https://quartz.jzhao.xyz/configuration#general-configuration
title: "Configuration"
description: "Quartz is meant to be extremely configurable, even if you don’t know any coding."
host: quartz.jzhao.xyz
favicon: ./static/icon.png
image: https://quartz.jzhao.xyz/configuration-og-image.webp
- `{ provider: 'google', tagId: '<your-google-tag>' }`: use Google Analytics;

TagID を発行する

Imgur Imgur

アカウントに新しい プロパティ を追加します。 プロパティ = アカウント内にある 1 つのサイト と自分は捉えました。

その後、作成したプロパティに対して発行された 測定 IDG-XXXXXXXX をコピーして取り置きます。

Imgur

Quartz4 側で環境変数を設定する

https://github.com/ganyariya/ganyariya-obsidian-quartz/pull/9

上記のように環境変数をつかって Google の Tag ID を設定します。 ganyariya-obsidian-quartz が public リポジトリであるためです。

Cloudflare Pages で環境変数を設定する

url: https://developers.cloudflare.com/workers/configuration/secrets/
title: "Secrets"
description: "Store sensitive information, like API keys and auth tokens, in your Worker."
host: developers.cloudflare.com
image: https://developers.cloudflare.com/dev-products-preview.png
url: https://developers.cloudflare.com/pages/configuration/build-configuration/#environment-variables
title: "Build configuration"
description: "You may tell Cloudflare Pages how your site needs to be built as well as where its output files will be located."
host: developers.cloudflare.com
image: https://developers.cloudflare.com/dev-products-preview.png
wrangler pages secret put GOOGLE_ANALYTICS_ID --project-name=ganyariya-obsidian-quartz

wrangler を利用して secret 環境変数として GOOGEL_ANALYTICS_ID を登録します。

Imgur

しばらく時間を置くと、きちんとアクセス数が取れるようになりました。

Imgur

まとめ

  • Public リポジトリの場合は 環境変数で設定する
  • wrangler で Secret として Google Analytics の TagID を設定する