Skip to content

Commit

Permalink
Merge pull request wevote#4138 from StevenSmith-code/GoogleTagManager
Browse files Browse the repository at this point in the history
[WV-523] Push voter_we_vote_id to GA4 from within WebApp user data [TEAM REVIEW]
  • Loading branch information
DaleMcGrew authored Oct 22, 2024
2 parents 1d890a3 + 8e9573f commit d292933
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ class App extends Component {
AppObservableStore.setGoogleAnalyticsPending(true);
setTimeout(() => {
const chosenTrackingId = AppObservableStore.getChosenGoogleAnalyticsTrackingID();
const weVoteTrackingId = webAppConfig.GOOGLE_ANALYTICS_TRACKING_ID === undefined ? '' : webAppConfig.GOOGLE_ANALYTICS_TRACKING_ID;
const weVoteTrackingId = webAppConfig.GOOGLE_ANALYTICS_TRACKING_ID || '';

if (chosenTrackingId && weVoteTrackingId) {
console.log('Google Analytics (2) ENABLED');
ReactGA.initialize([
Expand All @@ -258,16 +259,22 @@ class App extends Component {
} else {
console.log('Google Analytics did not receive a trackingID, NOT ENABLED');
}

const voterWeVoteId = VoterStore.getVoterWeVoteId();
ReactGA.gtag('set', 'voter', {
weVoteId: voterWeVoteId,
});
const weVoteGTMId = webAppConfig.GOOGLE_ADS_TRACKING_ID === undefined ? '' : webAppConfig.GOOGLE_ADS_TRACKING_ID;
const weVoteGTMId = webAppConfig.GOOGLE_TAG_MANAGER_ID || '';

if (weVoteGTMId) {
const tagManagerArgs = {
gtmId: weVoteGTMId,
dataLayer: {
weVoteId: voterWeVoteId,
},
};

console.log('Initializing Google Tag Manager with GTM ID:', weVoteGTMId);
TagManager.initialize(tagManagerArgs);
} else {
console.log('Google Tag Manager did not receive a valid GTM ID, NOT ENABLED');
}
}, 3000);
}
Expand Down

0 comments on commit d292933

Please sign in to comment.