Skip to content

[WV-1010] Added dataLayer code to Header items [FEEDBACK PROVIDED] #4337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 80 additions & 6 deletions src/js/components/Navigation/HeaderBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import withStyles from '@mui/styles/withStyles';
import PropTypes from 'prop-types';
import React, { Component, Suspense } from 'react';
import styled from 'styled-components';
// Zubin (WV-1010)
import TagManager from 'react-gtm-module';
import lookupPageNameAndPageTypeDict from '../../utils/lookupPageNameAndPageTypeDict';

import OrganizationActions from '../../actions/OrganizationActions';
import VoterActions from '../../actions/VoterActions';
import VoterGuideActions from '../../actions/VoterGuideActions';
Expand Down Expand Up @@ -239,10 +243,60 @@ class HeaderBar extends Component {
if (this.setStyleTimeout) clearTimeout(this.setStyleTimeout);
}

handleTabChange (newValue) {
handleTabChange (tabValue) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that you change the variable name of the incoming value to newTabValue over tabValue, since it clarifies that this is a new value we are switching to.

// Get the tab info from the mapping
console.log('handleTabChange ', tabValue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you make changes based on my comments in the pull request, and update this pull request with the [MERGE READY] title, please comment out all console.log lines you have added.

this.customHighlightSelector();
// console.log('handleTabChange ', newValue);
this.setState({ tabsValue: newValue });

// Get current user details
const voterWeVoteId = VoterStore.getVoterWeVoteId();
const stateCode = VoterStore.getVoterStateCode();
console.log('VoterStore results:', voterWeVoteId, stateCode);

// Get current page info
const { location: { pathname: currentPathname } } = window;
const currentPage = lookupPageNameAndPageTypeDict(currentPathname);
console.log('Source page object', currentPage);

// Map tabValue to destination pathname
const tabPathMappings = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tabPathMappings will need to be built up in the render method, just above the:

    return (
      <HeaderBarWrapper

around line 583. You will then pass it into the function handleTabChange. These tab values are dynamic based on the hide/show tab options, like if (isCordova() || inPrivateLabelMode) and else if (voterIsSignedIn).

1: '/ballot',
2: '/cs/',
3: '/friends',
4: '/challenges',
5: '/donate',
};

// Define destination info based on tab value
const destinationPathname = tabPathMappings[tabValue];
const destinationPage = lookupPageNameAndPageTypeDict(destinationPathname);
console.log('Destination page object: ', destinationPage);

// TODO:
// Replace switch statements with object lookup
// from calculatePageNameAndPageTypeDict

// Push to Tag Manager data layer
// TODO: Add statecode to userDetils
TagManager.dataLayer({
dataLayer: {
event: 'headerItemsClick',
userDetails: {
voterWeVoteId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change these two lines to alphabetical order & directly assign values from VoterStore:

stateCode: VoterStore.getVoterStateCode(),
userCohort: VoterStore.getAnalyticsUserCohort(),
voterWeVoteId: VoterStore.getVoterWeVoteId(),

and remove const voterWeVoteId = and const stateCode = above since we don't need them in local variables.

stateCode,
},
pageDetails: {
pageName: currentPage.pageName,
pageType: currentPage.pageType,
pathname: currentPathname,
},
destinationDetails: {
pageName: destinationPage.pageName,
pageType: destinationPage.pageType,
pathname: destinationPathname,
},
},
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to include this at the end of this function:
this.setState({ tabsValue: newTabValue });

}

handleResizeLocal () {
Expand Down Expand Up @@ -468,17 +522,24 @@ class HeaderBar extends Component {
const displayMenu = !isMobileScreenSize() || isTablet();
// console.log('HeaderBar isMobileScreenSize(), isTablet()', isMobileScreenSize(), isTablet());
// If NOT signed in, turn Discuss off and How It Works on

// Added hardcoded variables for ballot, candidates and challenges
let ballotValue;
let candidatesValue;
let discussValue;
let discussVisible;
let donateValue;
let donateVisible;
const friendsVisible = false; // 2023-09-04 Dale We are turning off Friends header link for now
let friendsValue;
let howItWorksValue;
const squadsVisible = nextReleaseFeaturesEnabled && isWebApp();
let squadsValue;
// let howItWorksVisible;
const howItWorksVisible = false;
if (isCordova() || inPrivateLabelMode) {
ballotValue = 1;
candidatesValue = 2;
discussValue = 99; // 4;
discussVisible = false; // We are turning off Discuss header link for now
donateValue = 99; // Donate not used in Cordova
Expand All @@ -487,6 +548,8 @@ class HeaderBar extends Component {
// howItWorksVisible = true;
squadsValue = 4;
} else if (voterIsSignedIn) {
ballotValue = 1;
candidatesValue = 2;
// If not Cordova and signed in, turn Donate & Discuss on, and How It Works off
// discussValue = 4;
// discussVisible = false; // We are turning off Discuss header link for now
Expand All @@ -495,7 +558,18 @@ class HeaderBar extends Component {
howItWorksValue = 99;
// howItWorksVisible = false;
squadsValue = 4;
} else if (friendsVisible) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't update all the values based only on if friendsVisible is true.

ballotValue = 1;
candidatesValue = 2;
friendsValue = 3;
donateValue = 5;
donateVisible = true;
howItWorksValue = 99;
// howItWorksVisible = false;
squadsValue = 4;
} else {
ballotValue = 1;
candidatesValue = 2;
// If not Cordova, and NOT signed in, turn Discuss off & How It Works on
discussValue = 99; // Not offered prior to sign in
discussVisible = false;
Expand Down Expand Up @@ -539,15 +613,15 @@ class HeaderBar extends Component {
>
<TabWithPushHistory
classes={isWebApp() ? { root: classes.tabRootBallotDesktop } : { root: classes.tabRootBallot }}
value={1}
value={ballotValue} // ballotValue added
change={this.handleTabChange}
id="ballotTabHeaderBar"
label="Ballot"
to="/ballot"
/>
<TabWithPushHistory
classes={isWebApp() ? { root: classes.tabRootCandidatesDesktop } : { root: classes.tabRootCandidates }}
value={2}
value={candidatesValue} // candidatesValue added
change={this.handleTabChange}
id="candidatesTabHeaderBar"
label="Candidates"
Expand All @@ -556,7 +630,7 @@ class HeaderBar extends Component {
{friendsVisible && (
<TabWithPushHistory
classes={isWebApp() ? { root: classes.tabRootFriendsDesktop } : { root: classes.tabRootFriends }}
value={3}
value={friendsValue}
change={this.handleTabChange}
id="friendsTabHeaderBar"
label="Friends"
Expand Down
2 changes: 1 addition & 1 deletion src/js/utils/lookupPageNameAndPageTypeDict.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const pageNameAndTypeSimpleDict = {
};

function calculatePageNameAndPageTypeDict (path) {
// console.log("gtmPageNameAndType, path:", path);
// console.log('gtmPageNameAndType, path:', path);
let settingsPageName = 'notSet'; // Per our naming convention for pageName, this would normally be 'NotSet' but I think the value of having settingsPageName being identical to settingsPageType will save us grief in the future.
let settingsPageType = 'notSet';

Expand Down