Compare commits

...

10 Commits

Author SHA1 Message Date
Daniel Roe
97764f1b98
Merge 1376da6a78 into edc299a043 2024-11-20 06:35:52 -05:00
renovate[bot]
edc299a043
chore(deps): update all non-major dependencies (main) (#29995)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-20 06:35:43 -05:00
renovate[bot]
ad3ab4d310
chore(deps): update all non-major dependencies (main) (#29986)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-19 23:36:17 -05:00
Jan-Niklas W.
9bf8465806
docs: update getting started to include WebStorm (#29845) 2024-11-19 20:39:14 +00:00
Julien Huang
1376da6a78
docs: remove useStyles 2024-06-28 22:42:33 +02:00
Daniel Roe
3d3d6f4c36
Merge branch 'main' into docs/scripts 2024-04-19 13:33:32 +03:00
Thorsten Kober
8ea1fa118b
docs: add overview for third parties (#25832)
Co-authored-by: Thorsten Kober <thorstenk@google.com>
Co-authored-by: Kara <kara@users.noreply.github.com>
Co-authored-by: Damian Głowala <damian.glowala.rebkow@gmail.com>
Co-authored-by: Houssein Djirdeh <houssein.djirdeh@gmail.com>
Co-authored-by: Julien Huang <julien.h.dev@gmail.com>
2024-02-22 11:30:49 +00:00
Thorsten Kober
ffda918f54
docs: add remaining third-party-capital api docs (#25592)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Houssein Djirdeh <houssein.djirdeh@gmail.com>
Co-authored-by: Julien Huang <julien.h.dev@gmail.com>
Co-authored-by: Damian Głowala <damian.glowala.rebkow@gmail.com>
2024-02-03 23:04:46 +00:00
Thorsten Kober
d0caae3c10
docs: add useGoogleAnalytics to api documentation (#25403) 2024-02-02 00:33:36 +00:00
Daniel Roe
73b8f07fec
chore: diverge 2024-01-23 15:53:29 +00:00
9 changed files with 366 additions and 10 deletions

View File

@ -248,7 +248,7 @@ jobs:
TEST_PAYLOAD: ${{ matrix.payload }} TEST_PAYLOAD: ${{ matrix.payload }}
SKIP_BUNDLE_SIZE: ${{ github.event_name != 'push' || matrix.env == 'dev' || matrix.builder == 'webpack' || matrix.context == 'default' || matrix.payload == 'js' || runner.os == 'Windows' }} SKIP_BUNDLE_SIZE: ${{ github.event_name != 'push' || matrix.env == 'dev' || matrix.builder == 'webpack' || matrix.context == 'default' || matrix.payload == 'js' || runner.os == 'Windows' }}
- uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2 - uses: codecov/codecov-action@985343d70564a82044c1b7fcb84c2fa05405c1a2 # v5.0.4
if: github.event_name != 'push' && matrix.env == 'built' && matrix.builder == 'vite' && matrix.context == 'default' && matrix.os == 'ubuntu-latest' && matrix.manifest == 'manifest-on' if: github.event_name != 'push' && matrix.env == 'built' && matrix.builder == 'vite' && matrix.context == 'default' && matrix.os == 'ubuntu-latest' && matrix.manifest == 'manifest-on'
with: with:
token: ${{ secrets.CODECOV_TOKEN }} token: ${{ secrets.CODECOV_TOKEN }}

View File

@ -21,8 +21,8 @@ Or follow the steps below to set up a new Nuxt project on your computer.
<!-- markdownlint-disable-next-line MD001 --> <!-- markdownlint-disable-next-line MD001 -->
#### Prerequisites #### Prerequisites
- **Node.js** - [`v18.0.0`](https://nodejs.org/en) or newer - **Node.js** - [`18.x`](https://nodejs.org/en) or newer (but we recommend the [active LTS release](https://github.com/nodejs/release#release-schedule))
- **Text editor** - We recommend [Visual Studio Code](https://code.visualstudio.com/) with the [official Vue extension](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (previously known as Volar) - **Text editor** - There is no IDE requirement, but we recommend [Visual Studio Code](https://code.visualstudio.com/) with the [official Vue extension](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (previously known as Volar) or [WebStorm](https://www.jetbrains.com/webstorm/), which, along with [other JetBrains IDEs](https://www.jetbrains.com/ides/), offers great Nuxt support right out-of-the-box.
- **Terminal** - In order to run Nuxt commands - **Terminal** - In order to run Nuxt commands
::note ::note

View File

@ -0,0 +1,132 @@
---
title: Third Parties
description: Learn how to optimize the performance of third-party resources using built-in composables and components.
navigation.icon: i-ph-users-duotone
---
Nuxt provides a number of composables and built-in libraries that make it easier -- and faster -- to load third-party resources in your application.
- `useScript`: Load any third-party script with server-side rendering support and a proxied API.
- `useStyles`: Load any third-party stylesheet using various asset strategies.
- Third-Party Wrappers: Wrapper components and composables that make it easier to include different popular third parties efficiently.
## How Third Parties Can Impact User Experience
Third parties are external resources included, but not directly controlled, by a site owner to add new functionality to a website. Popular examples of third parties include analytics, video embeds, maps, and social media integrations. Typically, third-party providers offer code snippets that can be added to the `head` or `body` section of the document.
Adding a single third-party resource to your Nuxt application might not have any noticeable impact on performance, but it can quickly begin to affect user experience if youre not careful. Many third parties, especially scripts, can take a relatively long time to download and execute, which can delay user interactivity and block page rendering.
Data from the Chrome User Experience Report shows that Nuxt sites that load more third-party resources have lower [Interaction to Next Paint](https://web.dev/articles/inp) (INP) and [Largest Contentful Paint](https://web.dev/articles/lcp) (LCP) pass rates.
![Chrome User Experience Report chart](/assets/docs/getting-started/third-parties/chart.png)
<sub>
source: Chrome User Experience Report,
date: October 2023,
devices: phone
</sub>
While the chart's correlation does not automatically indicate causation, lab experiments and data from the [Web Almanac](https://almanac.httparchive.org/en/2022/third-parties) provide further evidence that third-party resources significantly affect page performance.
## Optimizing Third Party Performance
In general, it can be difficult to determine the most optimal way to load different third-party resources. Nuxt provides a number of utilities to improve both the developer and user experience of loading third parties.
::callout
If you're using very popular third-party libraries, please check the [Third-Party Wrappers](#third-party-wrappers) section for available pre-configured solutions.
::
### useScript
The `useScript` composable enables you to load third-party scripts with SSR support and a proxied API. It works out of the box, requiring just a URL that points to the script resource.
```vue
<script setup lang="ts">
useScript({
src: 'https://www.example.com/script.js'
})
</script>
```
Optional triggers and asset strategies can be used to allow for more fine-grained control over how, and when, the script should be loaded. In the following example, the script will load once the promise provided in the trigger resolves (1 second later).
```vue
<script setup lang="ts">
useScript({
src: 'https://www.example.com/script.js',
trigger: new Promise((resolve) => {
setTimeout(() => { resolve() }, 1000)
})
})
</script>
```
:read-more{to="https://unhead.unjs.io/usage/composables/use-script "}
### Third-Party Wrappers
Nuxt provides a collection of utilities that are already configured to load and initialize popular third parties in the most performant way. These include:
- Composables to fetch scripts such as `useGoogleAnalytics` and `useGoogleTagManager`
- Components to load embeds such as `<GoogleMaps>` and `<YoutubeEmbed>`
#### Google Analytics
The `useGoogleAnalytics` composable allows you to integrate Google Analytics in your Nuxt application.
```vue
<script setup lang="ts">
useGoogleAnalytics({
id: 'GA-123456789-1'
})
</script>
```
:read-more{to="/docs/api/composables/use-google-analytics"}
#### Google Tag Manager
The `useGoogleTagManager` composable makes it easier to include Google Tag Manager in your Nuxt application.
```vue
<script setup lang="ts">
useGoogleTagManager({
id: 'GTM-ABCD12'
})
<script>
```
:read-more{to="/docs/api/composables/use-google-tag-manager"}
#### Google Maps
The `<GoogleMaps>` component initializes and displays a Google Map on your page using the Maps JavaScript API.
```vue
<template>
<div>
<GoogleMaps
api-key="API_KEY"
q="Space+Needle,Seattle+WA"
/>
</div>
</template>
```
:read-more{to="/docs/api/components/google-maps"}
#### YouTube Embed
The `<YoutubeEmbed>` component uses `lite-youtube-embed` under the hood to load and display a YouTube embed on your page faster.
```vue
<template>
<div>
<YoutubeEmbed
video-id="d_IFKP1Ofq0"
play-label="Play Video"
/>
</div>
</template>
```
:read-more{to="/docs/api/components/youtube-embed"}

View File

@ -0,0 +1,64 @@
---
title: "<GoogleMaps>"
description: A simple and performant Google Maps component.
links:
- label: Source
icon: i-simple-icons-github
to: https://github.com/nuxt/scripts-and-assets/blob/main/modules/nuxt-third-party-capital/src/runtime/components/GoogleMaps.ts
size: xs
---
The `<GoogleMaps>` component uses the [Maps JavaScript API](https://developers.google.com/maps/documentation/javascript) to load a map to your page.
::callout
You need an API key to use Google Maps.
::
## Example with Query
```vue
<template>
<div>
<GoogleMaps
api-key="API_KEY"
width="600"
height="400"
q="Space+Needle,Seattle+WA"
/>
</div>
</template>
```
## Example with Coordinates
```vue
<template>
<div>
<GoogleMaps
api-key="API_KEY"
width="600"
height="400"
:center="{ lat: 47.62065090386302, lng: -122.34932031714334 }"
/>
</div>
</template>
```
## Props
- `apiKey`: The [API key](https://developers.google.com/maps/documentation/javascript/get-api-key) to use Google Maps API.
- **type**: `string`
- **required**
- `q`: A query to search for.
- **type**: `string`
- `center`: Coordinates to set the map to
- **type**: `LatLng`
- `zoom`: Zoom value for the map
- **type**: `number`
- `width`: Width of the player
- **type**: `string`
- `height`: Height of the player
- **type**: `string`
- `params`: [Parameters](https://developers.google.com/maps/documentation/javascript/load-maps-js-api#optional_parameters) for the map.
Either a query (q) or coordinates (center) are needed for the map to function properly.

View File

@ -0,0 +1,39 @@
---
title: "<YoutubeEmbed>"
description: A simple and performant YouTube component.
links:
- label: Source
icon: i-simple-icons-github
to: https://github.com/nuxt/scripts-and-assets/blob/main/modules/nuxt-third-party-capital/src/runtime/components/YoutubeEmbed.ts
size: xs
---
The `<YoutubeEmbed>` component can be used to display a YouTube embed.
It uses [lite-youtube-embed](https://github.com/paulirish/lite-youtube-embed) to load significantly faster.
## Minimal Example
```vue
<template>
<div>
<YoutubeEmbed
video-id="d_IFKP1Ofq0"
play-label="Play"
/>
</div>
</template>
```
## Props
- `videoId`: The ID of the video
- **type**: `string`
- **required**
- `playLabel`: The label of the play button. This is for a11y purposes.
- **type**: `string`
- **required**
- `width`: Width of the player
- **type**: `string`
- `height`: Height of the player
- **type**: `string`
- `params`: [Parameters](https://developers.google.com/youtube/player_parameters#Parameters) for the player.

View File

@ -0,0 +1,61 @@
---
title: useGoogleAnalytics
description: useGoogleAnalytics allows you to load and initialize Google Analytics in your Nuxt app.
links:
- label: Source
icon: i-simple-icons-github
to: https://github.com/nuxt/scripts-and-assets/blob/main/modules/nuxt-third-party-capital/src/runtime/composables/googleAnalytics.ts
size: xs
---
The `useGoogleAnalytics` composable function allows you to include [Google Analytics 4](https://developers.google.com/analytics/devguides/collection/ga4) in your Nuxt application.
::callout
If Google Tag Manager is already included in your application, you can configure Google Analytics directly using it, rather than including Google Analytics as a separate component. Refer to the [documentation](https://developers.google.com/analytics/devguides/collection/ga4/tag-options#what-is-gtm) to learn more about the differences between Tag Manager and gtag.js.
::
## Minimal Example
```vue
<script setup>
useGoogleAnalytics({ id: 'GA-123456789-1' })
</script>
```
## Example with custom event
```vue
<script setup>
const { $script } = useGoogleAnalytics({
id: 'GA-123456789-1',
})
$script.waitForLoad().then(({ gtag }) => {
gtag('event', 'some_custom_event', { time: new Date() })
})
</script>
```
## Type
```ts
useGoogleAnalytics(options: ThirdPartyScriptOptions<GoogleAnalyticsOptions, GoogleAnalyticsApi>): ThirdPartyScriptApi<GoogleAnalyticsApi>
```
## Params
An object containing the following options:
- `id`: Google Analytics [measurement ID](https://support.google.com/analytics/answer/12270356).
- **type**: `string`
- **required**
## Return Values
An object that contains a special `$script` property that gives you access to the underlying script instance.
- `$script.waitForLoad`: A promise that resolves when the script is ready to use. It exposes `gtag` and `dataLayer`, which lets you interact with the API.
::callout
Learn more about [`useScript`](https://unhead.unjs.io/usage/composables/use-script).
::

View File

@ -0,0 +1,60 @@
---
title: useGoogleTagManager
description: useGoogleTagManager allows you to install Google Tag Manager in your Nuxt app.
links:
- label: Source
icon: i-simple-icons-github
to: https://github.com/nuxt/scripts-and-assets/blob/main/modules/nuxt-third-party-capital/src/runtime/composables/googleTagManager.ts
size: xs
---
The `useGoogleTagManager` composable allows you to install [Google Tag Manager](https://developers.google.com/tag-platform/tag-manager/web) in your Nuxt application.
## Minimal Example
```vue
<script setup>
useGoogleTagManager({ id: 'GTM-123456' })
</script>
```
## Example with Custom Event
```vue
<script setup>
const { $script } = useGoogleTagManager({
id: 'GTM-123456'
})
$script.waitForLoad().then(({ dataLayer }) => {
dataLayer.push({
event: 'pageview',
page_path: '/google-tag-manager'
})
})
</script>
```
## Type
```ts
useGoogleTagManager(options: ThirdPartyScriptOptions<GoogleTagManagerOptions, GoogleTagManagerApi>): ThirdPartyScriptApi<GoogleTagManagerApi>
```
## Params
An object containing the following options:
- `id`: Your GTM container ID. Usually starts with 'GTM-'.
- **type**: `string`
- **required**
## Return Values
An object that contains a special `$script` property that gives you access to the underlying script instance.
- `$script.waitForLoad`: A promise that resolves when the script is ready to use. It exposes `google_tag_manager` and `dataLayer`, which lets you interact with the API.
::callout
Learn more about [`useScript`](https://unhead.unjs.io/usage/composables/use-script).
::

View File

@ -91,7 +91,7 @@
"devalue": "5.1.1", "devalue": "5.1.1",
"eslint": "9.15.0", "eslint": "9.15.0",
"eslint-plugin-no-only-tests": "3.3.0", "eslint-plugin-no-only-tests": "3.3.0",
"eslint-plugin-perfectionist": "4.0.2", "eslint-plugin-perfectionist": "4.0.3",
"eslint-typegen": "0.3.2", "eslint-typegen": "0.3.2",
"h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e", "h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e",
"happy-dom": "15.11.6", "happy-dom": "15.11.6",
@ -118,7 +118,7 @@
"vue-router": "4.4.5", "vue-router": "4.4.5",
"vue-tsc": "2.1.10" "vue-tsc": "2.1.10"
}, },
"packageManager": "pnpm@9.13.2", "packageManager": "pnpm@9.14.1",
"engines": { "engines": {
"node": "^16.10.0 || >=18.0.0" "node": "^16.10.0 || >=18.0.0"
}, },

View File

@ -114,8 +114,8 @@ importers:
specifier: 3.3.0 specifier: 3.3.0
version: 3.3.0 version: 3.3.0
eslint-plugin-perfectionist: eslint-plugin-perfectionist:
specifier: 4.0.2 specifier: 4.0.3
version: 4.0.2(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3) version: 4.0.3(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
eslint-typegen: eslint-typegen:
specifier: 0.3.2 specifier: 0.3.2
version: 0.3.2(eslint@9.15.0(jiti@2.4.0)) version: 0.3.2(eslint@9.15.0(jiti@2.4.0))
@ -4373,8 +4373,8 @@ packages:
resolution: {integrity: sha512-brcKcxGnISN2CcVhXJ/kEQlNa0MEfGRtwKtWA16SkqXHKitaKIMrfemJKLKX1YqDU5C/5JY3PvZXd5jEW04e0Q==} resolution: {integrity: sha512-brcKcxGnISN2CcVhXJ/kEQlNa0MEfGRtwKtWA16SkqXHKitaKIMrfemJKLKX1YqDU5C/5JY3PvZXd5jEW04e0Q==}
engines: {node: '>=5.0.0'} engines: {node: '>=5.0.0'}
eslint-plugin-perfectionist@4.0.2: eslint-plugin-perfectionist@4.0.3:
resolution: {integrity: sha512-zWdgyg2SdHqhp/P9d9vKwo5qD9is28xMAGzBslHqkZz5mVIikjyz1qvuJ4yS7Wrsf4KlbGorORefb4Kbe7Puzg==} resolution: {integrity: sha512-CyafnreF6boy4lf1XaF72U8NbkwrfjU/mOf1y6doaDMS9zGXhUU1DSk+ZPf/rVwCf1PL1m+rhHqFs+IcB8kDmA==}
engines: {node: ^18.0.0 || >=20.0.0} engines: {node: ^18.0.0 || >=20.0.0}
peerDependencies: peerDependencies:
eslint: '>=8.0.0' eslint: '>=8.0.0'
@ -11519,7 +11519,7 @@ snapshots:
eslint-plugin-no-only-tests@3.3.0: {} eslint-plugin-no-only-tests@3.3.0: {}
eslint-plugin-perfectionist@4.0.2(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3): eslint-plugin-perfectionist@4.0.3(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3):
dependencies: dependencies:
'@typescript-eslint/types': 8.15.0 '@typescript-eslint/types': 8.15.0
'@typescript-eslint/utils': 8.15.0(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3) '@typescript-eslint/utils': 8.15.0(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)