Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
refactor(plugin-gtag): update gtag plugin to modern SPA recommendations #8143
refactor(plugin-gtag): update gtag plugin to modern SPA recommendations #8143
Changes from 4 commits
2382178
9ea3476
e3b9137
cda7b8a
961966e
b4780e2
1631f43
1bd3edf
bd0683e
88e9407
6d49f61
3cb8773
8ce5d72
be36601
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to understand the value of this abstraction 🤷♂️
What prevents someone to just do this directly in their code? (which would give them even more flexibility)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They can, I'm just an old school OOO programmer and will always provide strong types. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can agree with that, but the types should rather be provided by ambient definitions from official gtag TS bindings preferably.
If they don't provide those, I'd rather create our own types only, and not add an extra runtime api/hook
For example:
Isn't this good enough to provide strong types for our users? Do we really need the extra client api/hook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are gtag types published to DefinitelyTyped. Are you suggesting I get rid of the
Event
interface and replace it with something exported from there?I couldn't get that approach to work with my code. Its possible I was doing something wrong, but I always got a syntax error that gtag does not exist on the Window object.
In fact, the reason that I don't reference the Event interface in
src/types.d.ts
is because if I try to use an import statement in that file I get the same syntax error.The
onClick
approach you suggested above does indeed work, but it requires using ats-ignore
statement because gtag is not global. Our internal code analyzers get very angry when we do stuff like that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS - there is an unofficial React gtag package available. Its basically a port of the popular ReactGA plugin (that only works with old GA3 sites).
I thought about going that route instead but it seemed like a much bigger lift that this approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we ever import a third-party package, it should be either the official one of the DT one.
This one looks appropriate to me:
As far as I know adding a
@types/*
deps to the package should be enough for TS to find its ambient typedefsIf that's not the case you may be able to use
///
directive:https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html
/// <reference types="@types/gtag.js" />
On the Docusaurus repo we only care about providing a setup that TS agree with, not all the analyzers in the world 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it