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 Google Analytics #1049

Merged
merged 3 commits into from
Sep 27, 2022
Merged

Add Google Analytics #1049

merged 3 commits into from
Sep 27, 2022

Conversation

apedroferreira
Copy link
Member

@apedroferreira apedroferreira commented Sep 23, 2022

Closes #997

I think this basic integration should cover all the data we need for now.

@render
Copy link

render bot commented Sep 23, 2022

@apedroferreira apedroferreira self-assigned this Sep 23, 2022
@apedroferreira apedroferreira marked this pull request as ready for review September 26, 2022 15:22
@apedroferreira apedroferreira requested a review from a team September 26, 2022 15:22
Copy link
Contributor

@bytasv bytasv left a comment

Choose a reason for hiding this comment

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

Wondering if it made sense to use something like https://www.npmjs.com/package/nextjs-google-analytics ? - if I understood correctly we get pretty much the same functionality there

@apedroferreira
Copy link
Member Author

apedroferreira commented Sep 27, 2022

Wondering if it made sense to use something like https://www.npmjs.com/package/nextjs-google-analytics ? - if I understood correctly we get pretty much the same functionality there

I didn't know about this library, it doesn't seem very popular, maybe because it really isn't that much simpler/ easier to use than this integration, and does not provide any meaningful advantages?
Also I would argue that not relying on another external dependency gives us a bit more control and knowledge about what our integration does? Plus that way we don't have to rely on that dependency being actively mantained.

@bytasv
Copy link
Contributor

bytasv commented Sep 27, 2022

Wondering if it made sense to use something like https://www.npmjs.com/package/nextjs-google-analytics ? - if I understood correctly we get pretty much the same functionality there

I didn't know about this library, it doesn't seem very popular, maybe because it really isn't that much simpler/ easier to use than this integration, and does not provide any meaningful advantages? Also I would argue that not relying on another external dependency gives us a bit more control and knowledge about what our integration does? Plus that way we don't have to rely on that dependency being actively mantained.

That's fair. I just looked around and this popped up, I don't know about the popularity, but seems that it is somewhat actively maintained and from the initial impression it already does all what you had to implement so my thinking was that we might be just able to use that out of the box.
As for more control and knowledge about it - maybe you could be a little bit more specific? For me it would be enough to know that whatever the library is it does what I want it to do and if I start seeing some issues with it like maybe lack of functionality, that's then I would consider switching to home-made solution. Anyways these are just 2 cents from me and how I ended up there

@apedroferreira
Copy link
Member Author

That's fair. I just looked around and this popped up, I don't know about the popularity, but seems that it is somewhat actively maintained and from the initial impression it already does all what you had to implement so my thinking was that we might be just able to use that out of the box. As for more control and knowledge about it - maybe you could be a little bit more specific? For me it would be enough to know that whatever the library is it does what I want it to do and if I start seeing some issues with it like maybe lack of functionality, that's then I would consider switching to home-made solution. Anyways these are just 2 cents from me and how I ended up there

This implementation I made isn't too complex in my opinion, just analytics + page tracking + web vitals (not that web vitals are important for now, but they were just easy to add), so I don't think we'll have any issues maintaining it either.
It's not that the library you proposed has any big disadvantages, but as I've already implemented things this way I think we could keep it, as I don't see any advantages in using the library either, and there would be the effort in switching over.

The kind of issues that could come from using the library isn't too probable in the short-term but would be something like:

  • Google Analytics makes changes to their API
  • The library does not get updated / stops being actively maintained
  • We're stuck with the library unless we change to a manual implementation

@bytasv
Copy link
Contributor

bytasv commented Sep 27, 2022

As I mentioned that's fair enough, I'm not pushing to replace implementation, let's keep it as is, I just wanted to share how and why I was thinking of a library in the first place.
While your mentioned concerns can be valid in the situations that you described if the lib did what we need to do and it worked right now, none of that would matter and in the worse case scenario we could switch to home-made solution.
IMO this is something that we could/should keep an eye for in the future when we need to implement very common functionality and ask our selves whether we really want to write and maintain code ourselves (ideally that code should also be tested) if we could use something of the shelf (supposingly we could). I think it could sometimes be deceptive at first to treat that this is the only functionality that we would need for such thing and find ourselves adding more and more features just to end up recreating the same thing in house.

@apedroferreira
Copy link
Member Author

As I mentioned that's fair enough, I'm not pushing to replace implementation, let's keep it as is, I just wanted to share how and why I was thinking of a library in the first place. While your mentioned concerns can be valid in the situations that you described if the lib did what we need to do and it worked right now, none of that would matter and in the worse case scenario we could switch to home-made solution. IMO this is something that we could/should keep an eye for in the future when we need to implement very common functionality and ask our selves whether we really want to write and maintain code ourselves (ideally that code should also be tested) if we could use something of the shelf (supposingly we could). I think it could sometimes be deceptive at first to treat that this is the only functionality that we would need for such thing and find ourselves adding more and more features just to end up recreating the same thing in house.

Makes sense, let's keep an eye out for that sort of thing in the future.
Thanks for the feedback!

@apedroferreira apedroferreira merged commit 070cfda into master Sep 27, 2022
@apedroferreira apedroferreira deleted the add-ga branch September 27, 2022 17:04
@@ -167,6 +167,6 @@ export default /** @type {import('next').NextConfig} */ ({
source: '/:path*',
headers: securityHeaders,
},
]
Copy link
Member

Choose a reason for hiding this comment

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

@apedroferreira Any idea on how this passed the prettier CI check up until now?

Copy link
Member

Choose a reason for hiding this comment

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

Same with docs/next.config.js. It gets updated when I run yarn prettier:all

Copy link
Member Author

@apedroferreira apedroferreira Oct 4, 2022

Choose a reason for hiding this comment

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

not really, maybe it's not running for files with the .mjs extension?
i probably just saved the file and prettier added this

Copy link
Member Author

Choose a reason for hiding this comment

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

weird... if i run it locally this file always gets fixed

Copy link
Member

Choose a reason for hiding this comment

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

Did prettier get updated recently? CI only checks for changed files I believe. Perhaps we should run prettier:all in CI?

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, i merged this from renovatebot 735011e

that was probably it


const router = useRouter();

React.useEffect(() => {
Copy link
Member

Choose a reason for hiding this comment

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

@apedroferreira

  • How useful would this really be? We also have react-router on the editor, so the data wouldn't be exactly a good representation of user navigation throughout the app.
  • Did you verify we only send one event on hard reload?

Copy link
Member Author

@apedroferreira apedroferreira Oct 4, 2022

Choose a reason for hiding this comment

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

I took it from this example https://github.com/vercel/next.js/tree/canary/examples/with-google-analytics, just rechecked again and as far as I can tell:

  • hard reload only triggers one page view
  • client side router changes (creating a new connection for example) trigger page views too, probably because of hashChangeComplete

Copy link
Member Author

@apedroferreira apedroferreira Oct 4, 2022

Choose a reason for hiding this comment

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

seems to run for the iframe routes too, not sure if that's helpful

Copy link
Member

Choose a reason for hiding this comment

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

might make sense to disable for the app canvas

Copy link
Member Author

Choose a reason for hiding this comment

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

ok actually it turns out this effect is doing nothing at all... the page view events are being sent automatically.
i'll remove this effect and see if i can filter out events from the iframe

Copy link
Member Author

Choose a reason for hiding this comment

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

and because the page view events are sent automatically doesn't seem simple to filter out the ones from the canvas... - we can just ignore that data in the google analytics dashboard itself if we want to use page view data, im gonna make a PR that just removes the effect

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.

Add Google Analytics
3 participants