Skip to content
This repository has been archived by the owner on Aug 29, 2022. It is now read-only.

Story/google analytics #48

Merged
merged 18 commits into from
Aug 2, 2021
Merged

Story/google analytics #48

merged 18 commits into from
Aug 2, 2021

Conversation

ksiegel1923
Copy link
Collaborator

No description provided.

@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://salmon-moss-01b532c0f-48.eastus2.azurestaticapps.net

ga && pageTitleAsScreen(ga, t(screen.title));

//triggers a new event called page_change that shares your current page and next page
ga && pageChange(ga, t(screen.title), t(SCREENS[nextScreen].title));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want the translated version or the English version of the title? Should we perhaps ask design about this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably just English because the only people looking at this data will be the agency webmasters

Copy link
Collaborator

Choose a reason for hiding this comment

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

The changeScreen function gets called whenever a button is clicked, which doesn't always correspond to whether or not there's a new screen (i.e. if there's an error in one of the input fields, changeScreen will still get called even if the module doesn't actually move on to the next screen). We should probably move this to right before the setScreen gets called (I believe I refactored this changeScreen function quite a bit, so the placement would be something we'd probably have to figure out after merging that).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alternatively, I think we could also just add this to the useEffect where screen is a dependency? not 100% sure on this though

@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://salmon-moss-01b532c0f-48.eastus2.azurestaticapps.net

@@ -0,0 +1,21 @@
export function trackFutureResearch(ga) {
Copy link
Collaborator

@michellexliu michellexliu Jul 30, 2021

Choose a reason for hiding this comment

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

Instead of passing in ga to all of these methods, could we refactor this into a hook and just have useGA4React there since they all need ga anyways?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

);
Div.attributes.gaid && (gaid = Div.attributes.gaid.value);

const ga4react = new GA4React(gaid);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to create a new GA4React object every time the app is re-rendered (i.e. could we put this line outside of the renderApp function)? Not too familiar with how GA4React works, so I'm just wondering.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right now we are getting the gaid attribute within the render app which is why I put this here. I guess we could make the assumption that the user won't change their gaid so we wouldn't need to observe for it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm that's a good point— I guess we can keep it how it is just in case?


const headerRef = useRef(null);
const firstCheckRef = useRef(null);

const { t, i18n } = useTranslation();
const en = i18n.getFixedT("en");

const ga = useGA4React();

const ref = useRef();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should probably use a more descriptive name for this ref since there are other refs in this file

@ksiegel1923 ksiegel1923 reopened this Jul 30, 2021
import { useEffect, useState } from "react";

export default function moduleOnScreen(ref) {
const [isIntersecting, setIntersecting] = useState(false);
Copy link
Collaborator

@michellexliu michellexliu Jul 30, 2021

Choose a reason for hiding this comment

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

Could we move const [userViewed, setUserViewed] = useState(false); here, move checkVisible() to this file as well and change the if statement to if (!userViewed && isIntersecting), and then call checkVisible() after line 7? I think we could also combine this hook with the googleAnalytics() hook, so that we have easy access to the userViewedModule() method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The only problem with this is wouldn't it reset userViewed to false every time. We only want to send this event once

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think so— we never call setUserViewed(false) and since we're not actually changing/reloading the page or anything like that, moduleOnScreen(ref) only gets called once so the state should stay the same on all the screens; I don't think it's functionally any different than having the useState(false) for userViewed in Module.js.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll test it out and see what happens

@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://salmon-moss-01b532c0f-48.eastus2.azurestaticapps.net

@@ -130,6 +114,8 @@ function Module({ pagetitle, endpoint, dir }) {
focusFirstError();
} else {
updateOtherField();
pageTitleAsScreen;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we not need to provide any arguments here?

@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://salmon-moss-01b532c0f-48.eastus2.azurestaticapps.net

@@ -100,6 +114,8 @@ function Module({ pagetitle, endpoint, dir }) {
focusFirstError();
} else {
updateOtherField();
pageTitleAsScreen(en(screen.title));
pageChange(en(screen.title), en(SCREENS[nextScreen].title));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be en(screen.title, { page: pagetitle }) (same for other one) bc of the string interpolation in our translation config.

@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://salmon-moss-01b532c0f-48.eastus2.azurestaticapps.net

@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://salmon-moss-01b532c0f-48.eastus2.azurestaticapps.net

@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://salmon-moss-01b532c0f-48.eastus2.azurestaticapps.net

@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://salmon-moss-01b532c0f-48.eastus2.azurestaticapps.net

if there is no screen title or next screen title then look for the titleInverse
added {page: pageTitle} for english translation because of string interpolation
@github-actions
Copy link

github-actions bot commented Aug 1, 2021

Azure Static Web Apps: Your stage site is ready! Visit it here: https://salmon-moss-01b532c0f-48.eastus2.azurestaticapps.net

@michellexliu michellexliu merged commit 2d3314a into dev Aug 2, 2021
@michellexliu michellexliu deleted the story/google-analytics branch August 2, 2021 13:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants