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

feat(gatsby-plugin-google-analytics): add custom event helper #17612

Merged
merged 29 commits into from
Nov 13, 2019
Merged

feat(gatsby-plugin-google-analytics): add custom event helper #17612

merged 29 commits into from
Nov 13, 2019

Conversation

robmarshall
Copy link
Contributor

A custom event tracker for gatsby-plugin-google-analytics.

The user can import function "customTrackingEvent" from the plugin to call a tracking event on dynamic events or events that do not involve a new page loading.

An example would be tracking what filters have been used to dynamically sort items on a page. On each press of the sorting button, the event would fire, and then the items would be sorted. Allowing the website admin to see which combination of events are more used.

The user can provide the following values:

  • eventCategory
  • eventAction
  • eventLabel
  • eventValue

In response to this issue: #17603

I have added a basic test case, wasn't sure how else to test this. I have also added a short snippet for the documentation.

Let me know thoughts/improvements.

Thanks!

@robmarshall robmarshall requested review from a team as code owners September 13, 2019 14:49
Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

Thanks, this can come in handy for lots of users. A follow up could be to do a High Order component so we can wrap any component with a custom tracking event.

I wonder if we want to add an optional hitCallback parameter?

packages/gatsby-plugin-google-analytics/src/index.js Outdated Show resolved Hide resolved
packages/gatsby-plugin-google-analytics/src/index.js Outdated Show resolved Hide resolved
packages/gatsby-plugin-google-analytics/src/index.js Outdated Show resolved Hide resolved
packages/gatsby-plugin-google-analytics/src/index.js Outdated Show resolved Hide resolved
@wardpeet wardpeet changed the title Custom Event Tracking [gatsby-plugin-google-analytics] feat(gatsby-plugin-google-analytics): add custom event helper Sep 16, 2019
robmarshall and others added 3 commits September 16, 2019 15:25
Co-Authored-By: Ward Peeters <ward@coding-tech.com>
Co-Authored-By: Ward Peeters <ward@coding-tech.com>
Co-Authored-By: Ward Peeters <ward@coding-tech.com>
@robmarshall
Copy link
Contributor Author

hitCallback would be useful!

Any chance of getting this section pushed (so I can use it in a project I am working on) and then I can come back to this?

Removed spaces
@robmarshall
Copy link
Contributor Author

Completely missed that line comment! Sorted now.

Co-Authored-By: Marcy Sutton <marcy@gatsbyjs.com>
Copy link
Contributor

@coreyward coreyward left a comment

Choose a reason for hiding this comment

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

If we're going to wrap window.ga we should consider incorporating the remaining event options that Google Analytics supports like setting transport: beacon and nonInteraction: true as well: https://developers.google.com/analytics/devguides/collection/analyticsjs/events

robmarshall and others added 2 commits September 17, 2019 09:50
Co-Authored-By: Corey Ward <corey.atx@gmail.com>
Co-Authored-By: Ward Peeters <ward@coding-tech.com>
robmarshall and others added 2 commits September 18, 2019 10:01
Co-Authored-By: Michael <184316+muescha@users.noreply.github.com>
robmarshall and others added 2 commits September 18, 2019 19:49
Co-Authored-By: Michael <184316+muescha@users.noreply.github.com>
Co-Authored-By: Michael <184316+muescha@users.noreply.github.com>
@robmarshall
Copy link
Contributor Author

robmarshall commented Sep 26, 2019

Hey,

Working with packages inside massive repos is not something I am used to dealing with. How do I get this to a point that it can be merged?

Thanks

@wardpeet
Copy link
Contributor

I'll give it a final review :)

@robmarshall
Copy link
Contributor Author

@wardpeet What are your thoughts? Do I need to merge the upstream before it can be added?

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

This is getting pretty close! Some small changes to make tests pass and fix docs

packages/gatsby-plugin-google-analytics/README.md Outdated Show resolved Hide resolved
packages/gatsby-plugin-google-analytics/README.md Outdated Show resolved Hide resolved
packages/gatsby-plugin-google-analytics/src/utils.js Outdated Show resolved Hide resolved
packages/gatsby-plugin-google-analytics/README.md Outdated Show resolved Hide resolved
robmarshall and others added 4 commits October 11, 2019 11:13
Co-Authored-By: Ward Peeters <ward@coding-tech.com>
Co-Authored-By: Ward Peeters <ward@coding-tech.com>
Co-Authored-By: Ward Peeters <ward@coding-tech.com>
Co-Authored-By: Ward Peeters <ward@coding-tech.com>
@LekoArts LekoArts added the status: awaiting reviewer response A pull request that is currently awaiting a reviewer's response label Nov 13, 2019
@LekoArts
Copy link
Contributor

cc @wardpeet

@wardpeet wardpeet self-assigned this Nov 13, 2019
Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

@robmarshall thanks for creating this helper! Sorry, it took so long to get this merged.

Thank you! Let's ship it!

@wardpeet wardpeet merged commit 4e431f3 into gatsbyjs:master Nov 13, 2019
@robmarshall
Copy link
Contributor Author

Amazing! Thanks @wardpeet, looked over your cleanups, so much nicer! Thanks for the help :)

m-allanson added a commit to sdras/gatsby that referenced this pull request Nov 13, 2019
# By Sidhartha Chatterjee (6) and others
# Via Ward Peeters
* master: (95 commits)
  chore(release): Publish
  fix(gatsby): Use crossorigin for link in linkPrefetch strategy (gatsbyjs#17581)
  chore(www): Referrer policy (gatsbyjs#18621)
  feat(gatsby-source-shopify): support multi currency (gatsbyjs#19454)
  feat(gatsby-plugin-google-analytics): add custom event helper (gatsbyjs#17612)
  chore(docs): Add documentation for tailwindcss support (gatsbyjs#17747)
  Grammar fix (gatsbyjs#19473)
  Update sites.yml (gatsbyjs#19475)
  test(e2e-tests): add regression test for resolution conflicts… (gatsbyjs#19476)
  chore(release): Publish
  chore(docs): link to gatsby-plugin-catch-links in gatsby link… (gatsbyjs#19424)
  chore(gatsby): remove array.prototype.flatmap (gatsbyjs#19472)
  fix(gatsby): Re-use plugin resolution logic for theme dir resolution (gatsbyjs#19470)
  chore: Update stale action (gatsbyjs#19471)
  chore(showcase): add Kosmos to the showcase (gatsbyjs#19455)
  chore(showcase): Add Akshay Thakur's Portfolio (gatsbyjs#19370)
  chore(docs): Add note about file extensions (gatsbyjs#19464)
  chore(showcase): Add Quema Labs (gatsbyjs#19374)
  Update starters.yml (gatsbyjs#19375)
  fix(gatsby-transformer-remark): Check key before trying to get cache (gatsbyjs#19288)
  ...
rickiesmooth pushed a commit to rickiesmooth/gatsby that referenced this pull request Nov 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: awaiting reviewer response A pull request that is currently awaiting a reviewer's response
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants