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

add option to avoid tracking on initialisation #5

Merged
merged 3 commits into from
Oct 13, 2018

Conversation

antonk52
Copy link
Contributor

An extremely low size cost addon (+4b for gzipped) to allow avoid tracking on initialisation. Backwards compatible and particularly useful for SPAs that do not have server side rendering. Before with initial page load it would track a pageview event with default, in some cases incorrect document title. Will gladly discuss if you think this is a bad idea.

@lukeed
Copy link
Owner

lukeed commented Jan 15, 2018

Hey @antonk52, thanks!

I'm not sure that I really understand the need for this. Generally, the location/pathname is the only thing that matters for tracking -- the document.title is just there to match the official GA script, which means that it'd be "wrong" for a SPA app too. At this point, I think all that matters is being a tiny replacement for the official behavior.

I'll have to think about this a little bit more (brain not working today 😞) but feel free to try and convince me 😆

@antonk52
Copy link
Contributor Author

Thank you for taking a look. There are two main reasons I believe this is a good addition

  • Having the correct document titles as some people do use the page titles instead of page urls.
    If you visit an analytics page under BEHAVIOR / Overflow you can see that you can list top results with Page(url) or Page Title.

  • Avoiding tracking routes twice.

I can not think of a more generic case, so I will share my specific one. I found there are 3 main ways to do tracking in p/react apps:

  1. To listen on history change event, which sends a pageview event before one changes a page title
  2. To have a renderless Tracker component inside a route component which sends pageview event on route render
  3. To track in componentWillMount/componentDidMount method.

Regardless of which one I choose, using Ganalytics sends a pageview event when I first require it on new Ganalytics(...) to wrap in in a helper function, and then it sends another pageview event with any one of the three options I noted above.

A work around this could be to recreate ga on every route render and not to assign it to anything, but then when it comes to tracking a custom event it will send an additional pageview. Which does not seem like a good option.

I think it is a good tone to let a developer opt in or out whether one want to dispatch the initial pageview event or not.

Please let me know if this makes sense and it is not just me moaning 😅

@lukeed
Copy link
Owner

lukeed commented Jan 16, 2018

May I ask what router you're using within your P/React app?

@antonk52
Copy link
Contributor Author

I am using React Router v4.2.0

@kaylanm
Copy link

kaylanm commented Apr 13, 2018

Without this, there's also no way to sanitize the initial URL.

@lukeed
Copy link
Owner

lukeed commented Oct 13, 2018

Sorry for the super-delay on this.

I went into your branch to revert your initial commit & got the same functionality in here.

FWIW it's generally not good to (a) change version number; or (b) change built files in your PR.
The built files should not be in the repo, and that's my fault for part-(b).

Also included quick documentation.

Thank you! 🙌

@lukeed lukeed merged commit 5f91150 into lukeed:master Oct 13, 2018
@antonk52
Copy link
Contributor Author

Thank you. Awesome job with documentation too!

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.

3 participants