Skip to content

Commit

Permalink
feat: add google analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 30, 2024
1 parent 9d6d5b3 commit c28262d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
VITE_APP_NAME=$npm_package_name
VITE_APP_VERSION=$npm_package_version
VITE_DRIFTDB_URL=
VITE_GOOGLE_ANALYTICS_ID=
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
run: npm run build -- --base /${{ github.event.repository.name }}/
env:
VITE_DRIFTDB_URL: ${{ vars.DRIFTDB_URL }}
VITE_GOOGLE_ANALYTICS_ID: ${{ secrets.GOOGLE_ANALYTICS_ID }}

- name: Catch-all routes
run: cp dist/index.html dist/404.html
Expand Down
16 changes: 16 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@
<body>
<noscript>You need to enable JavaScript to play this game.</noscript>
<div id="root"></div>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script>
window['ga-disable-%VITE_GOOGLE_ANALYTICS_ID%'] = %DEV%;
window.dataLayer = window.dataLayer || [];
window.gtag = function () {
dataLayer.push(arguments);
};
gtag('js', new Date());
gtag('config', '%VITE_GOOGLE_ANALYTICS_ID%');
</script>
<script
async
src="https://www.googletagmanager.com/gtag/js?id=%VITE_GOOGLE_ANALYTICS_ID%"
></script>

<script type="module" src="src/index.tsx"></script>
</body>
</html>
1 change: 1 addition & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export const APP_VERSION = import.meta.env.VITE_APP_VERSION;
export const BASE_URL = import.meta.env.BASE_URL;
export const DEV = import.meta.env.DEV;
export const DRIFTDB_URL = import.meta.env.VITE_DRIFTDB_URL;
export const GOOGLE_ANALYTICS_ID = import.meta.env.VITE_GOOGLE_ANALYTICS_ID;
1 change: 1 addition & 0 deletions src/types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface ImportMetaEnv {
readonly VITE_APP_NAME: string;
readonly VITE_APP_VERSION: string;
readonly VITE_DRIFTDB_URL: string;
readonly VITE_VITE_GOOGLE_ANALYTICS_ID: string;
}

interface ImportMeta {
Expand Down

0 comments on commit c28262d

Please sign in to comment.