Skip to content
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

Initial GTM Migrations #456

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Initial GTM Migrations #456

wants to merge 7 commits into from

Conversation

TuukkaIkius
Copy link
Contributor

@TuukkaIkius TuukkaIkius commented Apr 29, 2024

Changes

  • Added Qualified script
  • Added Qualified page view tracking
  • Added an engagement based tracking event for Posthog
  • Added useIsEngaged hook for triggering engagement based analytic events

Merge Checklist:
Follows the same checklist as the linked Next PR

  • Disable Tags on GTM
    •  Twitter Audience
    •  Qualified - Pageview
    •  Posthog Download
    •  Posthog - Webinar - Thank You
    •  Posthog - Event - Form Submission - Subscribe
    •  Posthog - Event - Form Submission - Resource Download
    •  Posthog - Event - Form Submission - Contact Sales
    •  Posthog - 30s page view
    •  Bizible
    •  Clearbit
  • Merge the PRs

Testing checklist:

Copy link

vercel bot commented Apr 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 20, 2024 7:53am

@TuukkaIkius TuukkaIkius marked this pull request as ready for review April 29, 2024 13:01
Comment on lines +77 to +93
useEffect(() => {
setTimeout(() => {
setTimerReached(true);
}, 30000);
const routeChanged = () => {
setSecondPageReached(true);
};

router.events.on("routeChangeComplete", routeChanged);
return () => {
router.events.off("routeChangeComplete", routeChanged);
};
}, [router.events]);

useEffect(() => {
setIsEngaged(secondPageReached && timerReached);
}, [secondPageReached, timerReached]);
Copy link
Contributor

Choose a reason for hiding this comment

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

does this have to be two effects? From what I can tell from the logic, we are checking

  1. if the second page was reached
  2. if they've been here for 30 seconds

Since the timer isn't being reset anywhere, we can just put setIsEngaged into the timeout instead right? this removes extra state and an extra useEffect. something like this pseudo code below. what do you think?

  useEffect(() => {
    const timeout = setTimeout(() => {
      setIsEngaged(secondPageReached);
    }, 30000);

    const routeChanged = () => {
      setSecondPageReached(true);
    };

    router.events.on('routeChangeComplete', routeChanged);
    return () => {
      clearTimeout(timeout);
      router.events.off('routeChangeComplete', routeChanged);
    };
  }, [router.events, secondPageReached]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't quite match the criteria for tracking the engagement metrics.

With the current logic the timeout continues through page navigation and will trigger the tracking events when

  1. The User has spent 30 seconds on the site
  2. The user has visited at least two pages

With this proposed implementation the timeout resets on page navigation and the user would have to spend the full 30 seconds on the second (or any subsequent) page visited to be marked as an engaged viewer. This would cause a rapidly navigating user to not be marked as an engaged viewer.

Comment on lines +223 to +226
if (!isEngaged) return;
// Trigger engagement view events here
sendEngagedView();
}, [isEngaged]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have to return an isEngaged? Would it be better if we just sendEngagedView in the hook where we are setting engaged?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this mainly comes down to which solution you perceive as being more readable. I think the current solution keeps the hook readable by isolating the tracking logic from the tracking events.
But like I said, it's mostly personal preference at this point.

@TuukkaIkius TuukkaIkius mentioned this pull request Jun 24, 2024
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants