Skip to content

Commit 49c4f97

Browse files
committed
add google analytics
1 parent a71f58c commit 49c4f97

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Deploy GitHub Pages with Analytics
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3
14+
15+
- name: Inject Google Analytics
16+
run: |
17+
GA_SCRIPT="<script async src='https://www.googletagmanager.com/gtag/js?id=${{ secrets.GA_TRACKING_ID }}'></script><script>window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', '${{ secrets.GA_TRACKING_ID }}');</script>"
18+
sed -i "s#</head>#${GA_SCRIPT}</head>#g" index.html
19+
20+
- name: Deploy to GitHub Pages
21+
uses: peaceiris/actions-gh-pages@v3
22+
with:
23+
github_token: ${{ secrets.GITHUB_TOKEN }}
24+
publish_dir: ./

0 commit comments

Comments
 (0)