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

Sending Specific Page Views to GA4 #105

Open
jordanlambrecht opened this issue May 27, 2022 · 2 comments
Open

Sending Specific Page Views to GA4 #105

jordanlambrecht opened this issue May 27, 2022 · 2 comments

Comments

@jordanlambrecht
Copy link

I'm a little confused on the steps for this. I have the following on my _app.tsx:

  const tagManagerArgs = {
    gtmId: 'GTM-REDACTED',
    events: {
      sendUserInfo: 'userInfo',
    },
  }
  TagManager.initialize(tagManagerArgs)

And the following on a component called JobPost:

  const tagManagerArgs = {
    dataLayer: {
      page: `${frontMatter.title}`,
    },
    dataLayerName: 'PageDataLayer',
  }
  TagManager.dataLayer(tagManagerArgs)

The goal is to track page views for job postings as a datalayer so I can easily look at the most popular ones in GA4. How do I move this data into Tag Manager and then over to GA?

@kodiekenta
Copy link

what npm version did you use to install the package

@gubikmic
Copy link

This works for me

export default function SomePage() {
  window.dataLayer.push({
    event: 'pageview',
    page: {
      url: document.location.origin + document.location.pathname + document.location.search,
      title: 'SomePage',
    },
  })

  return (
    <>
      ...
    </>
  )
}

⚠️ In React strict mode (default for CRA) components render twice, so in DEV this will lead to two events firing

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

No branches or pull requests

3 participants