Skip to content

Commit

Permalink
feat(client): create sign_in and user_data GA events (#54074)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmaxed committed Mar 13, 2024
1 parent b458417 commit 8c75531
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
13 changes: 12 additions & 1 deletion client/src/analytics/call-ga.ts
Expand Up @@ -74,14 +74,25 @@ interface ChallengeFailedEvent {
challenge_files: ChallengeFiles;
}

interface UserData {
event: 'user_data';
user_id: string;
}

interface SignIn {
event: 'sign_in';
}

export type GAevent =
| DonationViewEvent
| DonationEvent
| DonationRelatedEvent
| RenderTimeEvent
| PageViewEvent
| ExperimentViewEvent
| ChallengeFailedEvent;
| ChallengeFailedEvent
| UserData
| SignIn;

export default function callGA(payload: GAevent) {
TagManager.dataLayer({
Expand Down
6 changes: 6 additions & 0 deletions client/src/components/Header/components/login.tsx
Expand Up @@ -7,6 +7,7 @@ import { createSelector } from 'reselect';

import envData from '../../../../config/env.json';
import { isSignedInSelector } from '../../../redux/selectors';
import callGA from '../../../analytics/call-ga';

const { apiLocation, homeLocation } = envData;

Expand Down Expand Up @@ -36,6 +37,11 @@ const Login = ({
data-test-label={dataTestLabel}
data-playwright-test-label='header-sign-in-button'
href={href}
onClick={() => {
callGA({
event: 'sign_in'
});
}}
>
<span className='login-btn-icon'>
<FontAwesomeIcon icon={faRightToBracket} />
Expand Down
33 changes: 29 additions & 4 deletions client/src/components/growth-book/growth-book-redux-connector.tsx
Expand Up @@ -5,16 +5,29 @@ import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import {
isSignedInSelector,
showMultipleProgressModalsSelector
showMultipleProgressModalsSelector,
userIdSelector,
userFetchStateSelector
} from '../../redux/selectors';
import { setShowMultipleProgressModals } from '../../redux/actions';
import { UserFetchState } from '../../redux/prop-types';
import callGA from '../../analytics/call-ga';

const mapStateToProps = createSelector(
isSignedInSelector,
showMultipleProgressModalsSelector,
(isSignedIn, showMultipleProgressModals: boolean) => ({
userIdSelector,
userFetchStateSelector,
(
isSignedIn: boolean,
showMultipleProgressModals: boolean,
userId: string,
userFetchState: UserFetchState
) => ({
isSignedIn,
showMultipleProgressModals
showMultipleProgressModals,
userId,
userFetchState
})
);

Expand All @@ -33,8 +46,20 @@ const GrowthBookReduxConnector = ({
children,
isSignedIn,
showMultipleProgressModals,
setShowMultipleProgressModals
userId,
setShowMultipleProgressModals,
userFetchState
}: GrowthBookReduxConnector) => {
// Send user id to GA
useEffect(() => {
if (userFetchState.complete && isSignedIn) {
callGA({
event: 'user_data',
user_id: userId
});
}
}, [userFetchState, userId, isSignedIn]);

const displayProgressModalMultipleTimes = useFeature(
'display_progress_modal_multiple_times'
).on;
Expand Down
1 change: 1 addition & 0 deletions client/src/redux/selectors.js
Expand Up @@ -5,6 +5,7 @@ export const savedChallengesSelector = state =>
userSelector(state).savedChallenges || [];
export const completedChallengesSelector = state =>
userSelector(state).completedChallenges || [];
export const userIdSelector = state => userSelector(state).id;
export const partiallyCompletedChallengesSelector = state =>
userSelector(state).partiallyCompletedChallenges || [];
export const currentChallengeIdSelector = state =>
Expand Down
6 changes: 6 additions & 0 deletions client/src/templates/Challenges/classic/lower-jaw.tsx
Expand Up @@ -20,6 +20,7 @@ import {
challengeMetaSelector,
completedPercentageSelector
} from '../redux/selectors';
import callGA from '../../../analytics/call-ga';

interface LowerJawPanelProps extends ShareProps {
resetButtonText: string;
Expand Down Expand Up @@ -298,6 +299,11 @@ const LowerJaw = ({
data-cy='sign-in-button'
href={`${apiLocation}/signin`}
className='btn-cta btn btn-block'
onClick={() => {
callGA({
event: 'sign_in'
});
}}
>
{t('learn.sign-in-save')}
</a>
Expand Down

0 comments on commit 8c75531

Please sign in to comment.