Skip to content

Commit 8719b0f

Browse files
committed
Add GA
1 parent 421763a commit 8719b0f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

scripts/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var constants = {
1414
_authorURL: 'Author Email or Website',
1515
_codeCredit: 'Author Code Credit',
1616
_githubRepo: 'Author Code Repo',
17+
_googleAnalytics: 'Google Analytics Tracking ID',
1718
// Map Settings
1819
_tileProvider: 'Basemap Tiles',
1920
_markercluster: 'Cluster Markers',

scripts/map.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,20 @@ $(window).on('load', function() {
738738
setTimeout(showMap, 50);
739739
}
740740
}
741+
742+
// Add Google Analytics if the ID exists
743+
var ga = getSetting('_googleAnalytics');
744+
console.log(ga)
745+
if ( ga && ga.length >= 10 ) {
746+
var gaScript = document.createElement('script');
747+
gaScript.setAttribute('src','https://www.googletagmanager.com/gtag/js?id=' + ga);
748+
document.head.appendChild(gaScript);
749+
750+
window.dataLayer = window.dataLayer || [];
751+
function gtag(){dataLayer.push(arguments);}
752+
gtag('js', new Date());
753+
gtag('config', ga);
754+
}
741755
}
742756

743757
/**

0 commit comments

Comments
 (0)