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(nuxt): prompt to install nuxt/scripts on usage #27010

Merged
merged 10 commits into from
May 3, 2024

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Apr 30, 2024

🔗 Linked issue

📚 Description

In preparation for nuxt/scripts initial release, this adds a prompt when adding a scripts: {} option to Nuxt config or using one of:

  • useConsentScriptTrigger
  • useAnalyticsPageEvent
  • useElementScriptTrigger
  • useScript
  • useScriptGoogleAnalytics
  • useScriptPlausibleAnalytics
  • useScriptCloudflareWebAnalytics
  • useScriptFathomAnalytics
  • useScriptMatomoAnalytics
  • useScriptGoogleTagManager
  • useScriptSegment
  • useScriptFacebookPixel
  • useScriptXPixel
  • useScriptIntercom
  • useScriptHotjar
  • useScriptStripe
  • useScriptLemonSqueezy
  • useScriptVimeoPlayer
  • useScriptYouTubeIframe
  • useScriptGoogleMaps
  • useScriptNpm

(We also need to add stub docs in #26854 for these, pointing to the source.)

cc: @harlan-zw - do these utilities look like the ones we should stub, or do you think there are any others to include here?

Copy link

stackblitz bot commented Apr 30, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@harlan-zw
Copy link
Contributor

harlan-zw commented May 1, 2024

Nice, this looks really good.

The only thing to consider is the stubs for registry scripts. Adding all of them is too much maintenance effort and bloat but maybe it's worth supporting useScriptGoogleAnalytics and useScriptGoogleTagManager.

Not too sure about components stubs, it would be for YoutubeEmbed and GoogleMaps.

@harlan-zw harlan-zw mentioned this pull request May 1, 2024
50 tasks
@danielroe
Copy link
Member Author

One thought: what do you think about @nuxt/scripts exporting the names of any key composables? We could inline the names, at least, directly from @nuxt/scripts in nuxt itself, which might avoid the need to update manually.

harlan-zw added a commit to nuxt/scripts that referenced this pull request May 1, 2024
@harlan-zw
Copy link
Contributor

harlan-zw commented May 1, 2024

v0.3.0 exports /registry which includes all of the Registry Scripts. The resolve may or may not work 🤔 It's also a little heavy as it's shipping the icons used for the DevTools and the docs, will trim it down if you're going to use it.

Unrelated to that, as part of this PR I wonder if you'd consider adding support for "stubbing" via Nuxt Config. I imagine a common way for people to use Nuxt Scripts between sites will just be to copy + paste config over.

For example my personal sites all use Fathom, I don't use any of the functions provided by Fathom itself so registering the script via nuxt config makes the most sense, I just need to provide the site config. This is similar to Nuxt sites using Plausible.

The config would look like

export default defineNuxtConfig({
  scripts: {
    registry: {
      fathomAnalytics: {
        site: 'SITE_ID'
      }
    }
  }
})

@harlan-zw
Copy link
Contributor

I reckon if we have the nuxt config stub we can skip the registry script composables.

@danielroe danielroe merged commit 589b403 into main May 3, 2024
58 checks passed
@danielroe danielroe deleted the feat/scripts-install-prompt branch May 3, 2024 12:57
This was referenced May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants