This is a GitHub action for injecting google analytics 4 tracking into a GitHub Pages static site during deployment.
This action uses python to inject your Google tag immediately before the tag.
name: Your Workflow
on:
release:
type: [published]
jobs:
deploy-to-github-pages:
# Using ubuntu latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
####### Build your project #######
### ...
### Note the folder holding your final HTML
### In this example its release/wwwroot
- name: Inject GA4 tracking code
uses: jake1164/ga4-ghpages@v1
with:
tracking_id: ${{ secrets.GA4_TRACKING_ID }} # example: G-11XXXXXXXX
file: release/wwwroot/index.html # your publish_dir to your html code before being published.
- name: Commit To GithubPages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: release/wwwroot
force_orphan: true
Input | Description |
---|---|
tracking_id |
Your Google tracking ID - ie G-11XXXXXXXX |
file |
Name and Path of the index.html file (or any file with a ) where you want your google tag injected |
No direct output apart from file with GA4 tag injected just before the tag.