Skip to content

Commit 965ff12

Browse files
committed
[WV 1097] Update ShareButton dataLayer after feedback
1 parent 76fa60b commit 965ff12

File tree

1 file changed

+96
-35
lines changed

1 file changed

+96
-35
lines changed

src/js/components/Share/ShareButtonDesktopTablet.jsx

Lines changed: 96 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -55,40 +55,59 @@ class ShareButtonDesktopTablet extends Component {
5555
let kindOfShare = 'BALLOT';
5656
let whatAndHowMuchToShare;
5757

58-
// Add debug logging
59-
console.log('Share button clicked');
60-
console.log('Current pathname:', window.location.pathname);
61-
console.log('VoterWeVoteId:', VoterStore.getVoterWeVoteId());
62-
63-
// Add dataLayer tracking
64-
const { location: { pathname: currentPathname } } = window;
65-
const page = lookupPageNameAndPageTypeDict(currentPathname);
66-
67-
const dataLayerObject = {
68-
event: 'shareClick',
69-
userDetails: {
70-
voterWeVoteId: VoterStore.getVoterWeVoteId(),
71-
},
72-
shareDetails: {
73-
kindOfShare,
74-
withOpinions: withOpinionsModified,
75-
},
76-
pageDetails: {
77-
pageName: page.pageName,
78-
pageType: page.pageType,
79-
pathname: currentPathname,
80-
},
81-
destinationDetails: {
82-
destinationPageName: 'ShareModal',
83-
destinationPageType: 'share',
84-
destinationPathname: currentPathname,
85-
},
86-
};
87-
88-
console.log('Pushing to dataLayer:', dataLayerObject);
89-
TagManager.dataLayer({
90-
dataLayer: dataLayerObject,
91-
});
58+
if (candidateShare) {
59+
kindOfShare = 'CANDIDATE';
60+
if (withOpinionsModified) {
61+
whatAndHowMuchToShare = 'candidateShareOptionsAllOpinions';
62+
AnalyticsActions.saveActionShareCandidateAllOpinions(VoterStore.electionId());
63+
} else {
64+
whatAndHowMuchToShare = 'candidateShareOptions';
65+
AnalyticsActions.saveActionShareCandidate(VoterStore.electionId());
66+
}
67+
} else if (measureShare) {
68+
kindOfShare = 'MEASURE';
69+
if (withOpinionsModified) {
70+
whatAndHowMuchToShare = 'measureShareOptionsAllOpinions';
71+
AnalyticsActions.saveActionShareMeasureAllOpinions(VoterStore.electionId());
72+
} else {
73+
whatAndHowMuchToShare = 'measureShareOptions';
74+
AnalyticsActions.saveActionShareMeasure(VoterStore.electionId());
75+
}
76+
} else if (officeShare) {
77+
kindOfShare = 'OFFICE';
78+
if (withOpinionsModified) {
79+
whatAndHowMuchToShare = 'officeShareOptionsAllOpinions';
80+
AnalyticsActions.saveActionShareOfficeAllOpinions(VoterStore.electionId());
81+
} else {
82+
whatAndHowMuchToShare = 'officeShareOptions';
83+
AnalyticsActions.saveActionShareOffice(VoterStore.electionId());
84+
}
85+
} else if (organizationShare) {
86+
kindOfShare = 'ORGANIZATION';
87+
if (withOpinionsModified) {
88+
whatAndHowMuchToShare = 'organizationShareOptionsAllOpinions';
89+
AnalyticsActions.saveActionShareOrganizationAllOpinions(VoterStore.electionId());
90+
} else {
91+
whatAndHowMuchToShare = 'organizationShareOptions';
92+
AnalyticsActions.saveActionShareOrganization(VoterStore.electionId());
93+
}
94+
} else if (readyShare) {
95+
kindOfShare = 'READY';
96+
if (withOpinionsModified) {
97+
whatAndHowMuchToShare = 'readyShareOptionsAllOpinions';
98+
AnalyticsActions.saveActionShareReadyAllOpinions(VoterStore.electionId());
99+
} else {
100+
whatAndHowMuchToShare = 'readyShareOptions';
101+
AnalyticsActions.saveActionShareReady(VoterStore.electionId());
102+
}
103+
// Default to ballot
104+
} else if (withOpinionsModified) {
105+
whatAndHowMuchToShare = 'ballotShareOptionsAllOpinions';
106+
AnalyticsActions.saveActionShareBallotAllOpinions(VoterStore.electionId());
107+
} else {
108+
whatAndHowMuchToShare = 'ballotShareOptions';
109+
AnalyticsActions.saveActionShareBallot(VoterStore.electionId());
110+
}
92111

93112
if (candidateShare) {
94113
kindOfShare = 'CANDIDATE';
@@ -148,8 +167,50 @@ class ShareButtonDesktopTablet extends Component {
148167
AppObservableStore.setShowShareModal(true);
149168
AppObservableStore.setWhatAndHowMuchToShare(whatAndHowMuchToShare);
150169
const { pathname } = window.location;
170+
const pathnameWithModalShare = `${pathname}${pathname.endsWith('/') ? '' : '/'}modal/share`;
171+
172+
// Add debug logging
173+
console.log('Share button clicked');
174+
console.log('Current pathname:', pathname);
175+
console.log('Destination pathname:', pathnameWithModalShare);
176+
console.log('VoterWeVoteId:', VoterStore.getVoterWeVoteId());
177+
178+
// Add dataLayer tracking
179+
const page = lookupPageNameAndPageTypeDict(pathname);
180+
const modalPage = lookupPageNameAndPageTypeDict(pathnameWithModalShare);
181+
182+
const dataLayerObject = {
183+
event: 'action',
184+
actionDetails: {
185+
actionType: 'openModal',
186+
buttonId: `shareButtonDesktopTablet-${kindOfShare.toLowerCase()}`,
187+
},
188+
userDetails: {
189+
voterWeVoteId: VoterStore.getVoterWeVoteId(),
190+
},
191+
shareDetails: {
192+
kindOfShare,
193+
whatAndHowMuchToShare,
194+
withOpinions: withOpinionsModified,
195+
},
196+
pageDetails: {
197+
pageName: page.pageName,
198+
pageType: page.pageType,
199+
pathname,
200+
},
201+
destinationDetails: {
202+
destinationPageName: modalPage.pageName,
203+
destinationPageType: modalPage.pageType,
204+
destinationPathname: pathnameWithModalShare,
205+
},
206+
};
207+
208+
console.log('Pushing to dataLayer:', dataLayerObject);
209+
TagManager.dataLayer({
210+
dataLayer: dataLayerObject,
211+
});
212+
151213
if (!stringContains('/modal/share', pathname) && isWebApp()) {
152-
const pathnameWithModalShare = `${pathname}${pathname.endsWith('/') ? '' : '/'}modal/share`;
153214
// console.log('Navigation ShareButtonDesktopTablet openShareModal ', pathnameWithModalShare)
154215
historyPush(pathnameWithModalShare, false, true);
155216
}

0 commit comments

Comments
 (0)