Skip to content

Latest commit

 

History

History
58 lines (44 loc) · 1.96 KB

README.md

File metadata and controls

58 lines (44 loc) · 1.96 KB

ga4-ghpages Action

GA4 Logo

Inject your Google Analytics tracking tag into github pages


This is a GitHub action for injecting google analytics 4 tracking into a GitHub Pages static site during deployment.

Usage

This action uses python to inject your Google tag immediately before the tag.

Example workflow

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

Inputs

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

Outputs

No direct output apart from file with GA4 tag injected just before the tag.