-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ac88d5
commit 0453009
Showing
5 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"GA_KEY": "Test-Google-Analytics-Key-Replace-Me" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// analytics.js | ||
(function() { | ||
// Fetch the runtime configuration | ||
fetch('config/config.json') | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Configuration file not found'); | ||
} | ||
return response.json(); | ||
}) | ||
.then(config => { | ||
if (!config.GA_KEY) { | ||
throw new Error('GA_KEY is missing in the configuration'); | ||
} | ||
|
||
// Create the script tag for Google Tag Manager | ||
const scriptTag = document.createElement('script'); | ||
scriptTag.async = true; | ||
scriptTag.src = `https://www.googletagmanager.com/gtag/js?id=${config.GA_KEY}`; | ||
document.head.appendChild(scriptTag); | ||
|
||
// Initialize Google Analytics | ||
window.dataLayer = window.dataLayer || []; | ||
|
||
function gtag() { dataLayer.push(arguments); } | ||
|
||
gtag('js', new Date()); | ||
gtag('config', config.GA_KEY); | ||
}) | ||
.catch(error => console.warn('GA setup skipped:', error.message)); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters