Skip to content

fix(tpc): custom feature detection flags #113

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

Merged
merged 9 commits into from
Jul 12, 2024
Merged

Conversation

huang-julien
Copy link
Member

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR add feature detection for tpc composables. It also removes augmentWindowTypes to make it default

Copy link

vercel bot commented Jun 26, 2024

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
scripts-docs βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Jul 11, 2024 7:09pm
scripts-playground βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Jul 11, 2024 7:09pm

@huang-julien huang-julien changed the title frat(tpc): add feature detection feat(tpc): add feature detection Jun 26, 2024
Copy link
Member Author

@huang-julien huang-julien left a comment

Choose a reason for hiding this comment

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

@flashdesignory do you need it in other components ?

@flashdesignory
Copy link
Contributor

@flashdesignory do you need it in other components ?

once GoogleMaps and Youtube is integrated, we should also add the feature detection there πŸ™

Copy link
Contributor

@flashdesignory flashdesignory left a comment

Choose a reason for hiding this comment

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

LGTM πŸš€

@huang-julien
Copy link
Member Author

yes we need to discuss about theses components at the next meeting :)

@harlan-zw
Copy link
Collaborator

Aren't these already implemented as part of https://github.com/nuxt/scripts/blob/main/src/runtime/composables/useScript.ts#L26 ?

@flashdesignory
Copy link
Contributor

we want to differentiate between all nuxt scripts and the third-party-capital integrations.
Additionally, the naming convention that is currently used, diverged from the flags introduced in the initial pr.
This results in a mismatch between nuxt script and chrome flags.

@harlan-zw
Copy link
Collaborator

harlan-zw commented Jun 26, 2024

we want to differentiate between all nuxt scripts and the third-party-capital integrations.

You can just use the key? ga / gtm is tpc

Additionally, the naming convention that is currently used, diverged from the flags introduced in the initial pr.
This results in a mismatch between nuxt script and chrome flags.

Yes, this was intentional. What / which chrome flags are you referring to?

@flashdesignory
Copy link
Contributor

flashdesignory commented Jun 26, 2024

We implemented flags in Chrome that we can use to pull usage data.
These flags currently exist:

nuxt-third-parties-gtm
nuxt-third-parties-ga
nuxt-third-parties-GoogleMaps
nuxt-third-parties-YoutubeEmbed

previous pr: https://github.com/nuxt/third-party-capital/pull/53

@harlan-zw
Copy link
Collaborator

We implemented flags in Chrome that we can use to pull usage data. These flags currently exist:

nuxt-third-parties-gtm
nuxt-third-parties-ga
nuxt-third-parties-GoogleMaps
nuxt-third-parties-YoutubeEmbed

previous pr: nuxt/third-party-capital#53

Is it possible to update the flags? It would make more sense for the scope prefix to match the module name.

It's a bit clunky to try and support both naming conventions

@huang-julien
Copy link
Member Author

any progress on this ?

@flashdesignory
Copy link
Contributor

@huang-julien - thanks for following up.

I'd still like to use the updated naming convention for the following reasons:

  1. we are more interested in the third-party-capital integrations
  2. updating flags that are already deployed in chrome is time intense
  3. more granular usage reports available, if we add all Nuxt script flags to chrome in the future as well

Personally, I think the work is doable, since we're not dealing with a large number of third-parties anytime soon.
Keeping both group of flags updated seems reasonable.

@huang-julien
Copy link
Member Author

the updated naming convention

Are you talking about nuxt-third-parties-${id} ? @harlan-zw wdyt if we move to this convention in useScript ?

@flashdesignory
Copy link
Contributor

the updated naming convention

Are you talking about nuxt-third-parties-${id} ? @harlan-zw wdyt if we move to this convention in useScript ?

correct, the only thing I am not sure about is if the ids match.
We previously used "ga" and "gtm"

@huang-julien
Copy link
Member Author

huang-julien commented Jul 3, 2024

Yes google analytics was using gtag instead of ga. It's now fixed but shouldn't the main script in the data of tpc have the same id used for feature detection ?

@harlan-zw i'm changing the feature detection to nuxt-third-parties-${id}, are you okay with it ?

@harlan-zw
Copy link
Collaborator

harlan-zw commented Jul 4, 2024

we are more interested in the third-party-capital integrations

This is fine, I don't see how using different keys stops you from doing this.

updating flags that are already deployed in chrome is time intense

It seems like this is just a matter of changing a string but maybe you can clarify further exactly how much work are we talking? Ideally these wouldn't of been set initially until we were close to making the module public, breaking changes should have been expected.

more granular usage reports available, if we add all Nuxt script flags to chrome in the future as well

Not sure how using different keys helps with this.

The reason why I prefer a properly named prefix:

  • Chrome may not be the only ones using these flags
  • Clear where the scripts are being loaded from

Keep in mind that even if we merge this, Youtube and Google Maps will still be broken.

@flashdesignory
Copy link
Contributor

Maybe I am missing something 🀷.
If I understand the current implementations correctly, a user has two options to use Google Analytics and Google Tag Manager:

  1. the default nuxt script version
  2. the tpc integration (if the user opts into using that).

Is that assumption correct?

If so, and I am using the same flags from nuxt script, how can I differentiate if a user uses 1) or 2) ?
Using the same flag wouldn't give me a correct signal.
Adding an additional flag (with this pr), would allow me to just get the usage of the tpc integrations.

@harlan-zw
Copy link
Collaborator

harlan-zw commented Jul 7, 2024

We only give one option of which to use, it would be confusing otherwise and add no value to the end user.

GA and GTM is using TPC.

@housseindjirdeh
Copy link
Contributor

It seems like this is just a matter of changing a string but maybe you can clarify further exactly how much work are we talking? Ideally these wouldn't of been set initially until we were close to making the module public, breaking changes should have been expected.

You're right, it's a quick string change. The larger concern is that any changes in Chromium will take a while before it hits stable (likely well after this module goes public and gathers adoption). We wanted to get a bit ahead of the curve by naming these strings before the module ships since it can take months to see the change in stable browser.

@harlan-zw
Copy link
Collaborator

Thanks for clarifying, In this case, I'd consider this PR okay to go ahead with. Do we need to handle GTM as well @huang-julien

@huang-julien
Copy link
Member Author

tag manager has already gtm as key in tpc.

@huang-julien huang-julien marked this pull request as ready for review July 11, 2024 11:52
@@ -25,7 +25,7 @@ export function useScript<T extends Record<string | symbol, any>>(input: UseScri
if (!nuxtApp._scripts?.[id]) {
performance?.mark?.('mark_feature_usage', {
detail: {
feature: `nuxt-scripts:${id}`,
feature: `nuxt-third-parties-${id}`,
Copy link
Collaborator

@harlan-zw harlan-zw Jul 11, 2024

Choose a reason for hiding this comment

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

I'd prefer if the non-TPC scripts used the old key name.

So could we add a config key on NuxtUseScriptOption performanceMarkFeature which can be added as deprecated, then we provide the full key via the TPC scripts

feature: options?.performanceMarkFeature || `nuxt-scripts:${id}`,

Copy link
Member Author

Choose a reason for hiding this comment

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

i'm good with 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.

as deprecated ? Maybe as internal if you don't want it to be public

src/tpc/utils.ts Outdated
@@ -86,7 +87,7 @@ declare global {
chunks.push(`
export function ${input.scriptFunctionName}<T extends ${input.tpcTypeImport}>(_options?: Input) {
${functionBody.join('\n')}
return useRegistryScript${hasParams ? '<T, typeof OptionSchema>' : ''}('${input.tpcKey}', options => ({
return useRegistryScript${hasParams ? '<T, typeof OptionSchema>' : ''}('${input.registryId ?? input.tpcKey}', options => ({
Copy link
Collaborator

@harlan-zw harlan-zw Jul 11, 2024

Choose a reason for hiding this comment

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

we then pass in

performanceMarkFeature: 'nuxt-third-parties-${id}`,

@flashdesignory
Copy link
Contributor

@huang-julien - if you're using the key from tpc as the id, do we need to handle the Google Analytics key ?

https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/timing/performance_mark.cc;l=157-161?q=nuxt-third-parties&ss=chromium

https://github.com/GoogleChromeLabs/third-party-capital/blob/main/src/third-parties/google-analytics/data.json

I remember you mentioned that these are different and if that's the case, I think we can rename that one in tpc (@housseindjirdeh ).

@huang-julien huang-julien marked this pull request as draft July 11, 2024 18:52
@huang-julien huang-julien marked this pull request as ready for review July 11, 2024 20:52
@harlan-zw harlan-zw changed the title feat(tpc): add feature detection fix(tpc): custom feature detection flags Jul 12, 2024
@harlan-zw harlan-zw merged commit 4c35f73 into main Jul 12, 2024
4 checks passed
@harlan-zw harlan-zw deleted the feat/feature_detection branch July 12, 2024 03:01
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.

4 participants