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

Google analytics tracks pages, but not always the path and the title are from the same page. Sometimes a visitor visits "/" but the title of another url. #9139

Closed
hackhat opened this issue Oct 16, 2018 · 7 comments
Labels
help wanted Issue with a clear description that the community can help with. stale? Issue that may be closed soon due to the original author not responding any more. status: needs more info Needs triaging and reproducible examples or more information to be resolved status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting.

Comments

@hackhat
Copy link

hackhat commented Oct 16, 2018

Description

Google analytics tracks pages, but not always the path and the title are from the same page. Sometimes a visitor visits "/" but the title of another url.

Looks like the url is correct but the title is from the previous page I've seen. I'm using import { Link } from 'gatsby' for the links.

Steps to reproduce

Created default app:

Add Google analytics script:

{
  resolve: `gatsby-plugin-google-analytics`,
  options: {
    trackingId: "UA-12420899-9",
    // Puts tracking script in the head instead of the body
    head: false,
    // Setting this parameter is optional
    anonymize: false,
    // Setting this parameter is also optional
    respectDNT: false ,
    // Avoids sending pageview hits from custom paths
    exclude: [],
    // Any additional create only fields (optional)
    sampleRate: 100,
    siteSpeedSampleRate: 100,
    cookieDomain: "www.freereikicourse.com",
  },
},

Add helmet in your page template:

    <Helmet
      title={frontmatter.title}
      meta={[
        { name: 'description', content: frontmatter.description },
        { name: 'keywords', content: frontmatter.keywords },
      ]}
    >
      <html lang="en"/>
    </Helmet>

Expected result

All pages should have the path matching with the title.

Actual result

Google analytics tracks pages, but not always the path and the title are from the same page. Sometimes a visitor visits "/" but the title of another url.

Environment

gatsby info --clipboard:

    System:
        OS: Windows 10
        CPU: x64 Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz
      Binaries:
        Yarn: 1.9.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
        npm: 5.5.1 - C:\Program Files\nodejs\npm.CMD
      Browsers:
        Edge: 42.17134.1.0
      npmPackages:
        gatsby: ^2.0.19 => 2.0.21
        gatsby-plugin-catch-links: ^2.0.4 => 2.0.4
        gatsby-plugin-emotion: ^2.0.5 => 2.0.5
        gatsby-plugin-google-analytics: ^2.0.6 => 2.0.6
        gatsby-plugin-manifest: ^2.0.5 => 2.0.5
        gatsby-plugin-offline: ^2.0.5 => 2.0.6
        gatsby-plugin-react-helmet: ^3.0.0 => 3.0.0
        gatsby-plugin-sharp: ^2.0.6 => 2.0.6
        gatsby-plugin-typescript: ^2.0.0 => 2.0.0
        gatsby-plugin-web-font-loader: ^1.0.4 => 1.0.4
        gatsby-remark-images: ^2.0.4 => 2.0.4
        gatsby-source-filesystem: ^2.0.3 => 2.0.3
        gatsby-transformer-remark: ^2.1.7 => 2.1.7
@kakadiadarpan
Copy link
Contributor

@hackhat can you provide a minimal reproduction repo for this issue?

@kakadiadarpan kakadiadarpan added status: needs more info Needs triaging and reproducible examples or more information to be resolved status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. labels Nov 14, 2018
@hackhat
Copy link
Author

hackhat commented Nov 16, 2018

I don't, but basically the problem happens in the template because the tracker sends the pageview before the markdown page is loaded. The title of the page is only updated when the markdown is downloaded, because the title is in the markdown. But is tracked as soon as that url is changed. I wonder how this doesn't happen in other places...

@lloydh
Copy link
Contributor

lloydh commented Dec 7, 2018

As @hackhat says this is happening because gatsby-plugin-google-analytics is sending off the pageview in Gatsby's onRouteUpdate hook, before react-helmet has rendered the new page title.

The issue affects SPA's generally and is discussed here. A hacky fix is arbitrarily delaying GA to allow the title to update. I'd like to see a discussion that results in a more elegant solution.

@lloydh lloydh added the help wanted Issue with a clear description that the community can help with. label Dec 7, 2018
@hackhat
Copy link
Author

hackhat commented Dec 10, 2018

Me too. I wonder how come it doesn't affect more people?

@joakimbording
Copy link

Same problem here. Using the gatsby-plugin-google-analytics cause page view reports in GA with the correct path and previous pages title.

@gatsbot
Copy link

gatsbot bot commented Feb 12, 2019

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

Thanks for being a part of the Gatsby community! 💪💜

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Feb 12, 2019
wardpeet added a commit that referenced this issue Feb 15, 2019
There is still a problem with title and path not being correct while navigating across a page.

As referenced in: #9139
Solution made in:  #2478 and #3362

For some reason the previous solution is being overwritten

Co-authored-by: Ward Peeters <ward@coding-tech.com>
@wardpeet
Copy link
Contributor

wardpeet commented Feb 15, 2019

The PR got merged :) Big thank you to @jorgenblindheim
should be fixed in next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issue with a clear description that the community can help with. stale? Issue that may be closed soon due to the original author not responding any more. status: needs more info Needs triaging and reproducible examples or more information to be resolved status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting.
Projects
None yet
Development

No branches or pull requests

5 participants