diff --git a/Cargo.lock b/Cargo.lock index 6fb0fa90b01fd..5885a56113554 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -321,7 +321,7 @@ dependencies = [ [[package]] name = "auto-hash-map" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "serde", "smallvec", @@ -3528,7 +3528,7 @@ dependencies = [ [[package]] name = "node-file-trace" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "serde", @@ -7639,7 +7639,7 @@ dependencies = [ [[package]] name = "turbo-tasks" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "async-trait", @@ -7671,7 +7671,7 @@ dependencies = [ [[package]] name = "turbo-tasks-build" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "cargo-lock", @@ -7683,7 +7683,7 @@ dependencies = [ [[package]] name = "turbo-tasks-bytes" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "bytes", @@ -7698,7 +7698,7 @@ dependencies = [ [[package]] name = "turbo-tasks-env" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "dotenvs", @@ -7712,7 +7712,7 @@ dependencies = [ [[package]] name = "turbo-tasks-fetch" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -7729,7 +7729,7 @@ dependencies = [ [[package]] name = "turbo-tasks-fs" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "auto-hash-map", @@ -7759,7 +7759,7 @@ dependencies = [ [[package]] name = "turbo-tasks-hash" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "base16", "hex", @@ -7771,7 +7771,7 @@ dependencies = [ [[package]] name = "turbo-tasks-macros" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "convert_case 0.6.0", @@ -7785,7 +7785,7 @@ dependencies = [ [[package]] name = "turbo-tasks-macros-shared" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "proc-macro2", "quote", @@ -7795,7 +7795,7 @@ dependencies = [ [[package]] name = "turbo-tasks-malloc" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "mimalloc", ] @@ -7803,7 +7803,7 @@ dependencies = [ [[package]] name = "turbo-tasks-memory" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "auto-hash-map", @@ -7828,7 +7828,7 @@ dependencies = [ [[package]] name = "turbopack" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "async-recursion", @@ -7859,7 +7859,7 @@ dependencies = [ [[package]] name = "turbopack-binding" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "auto-hash-map", "mdxjs", @@ -7899,7 +7899,7 @@ dependencies = [ [[package]] name = "turbopack-build" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -7921,7 +7921,7 @@ dependencies = [ [[package]] name = "turbopack-cli-utils" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "clap 4.4.2", @@ -7945,7 +7945,7 @@ dependencies = [ [[package]] name = "turbopack-core" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "async-recursion", @@ -7975,7 +7975,7 @@ dependencies = [ [[package]] name = "turbopack-css" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "async-trait", @@ -7997,7 +7997,7 @@ dependencies = [ [[package]] name = "turbopack-dev" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -8021,7 +8021,7 @@ dependencies = [ [[package]] name = "turbopack-dev-server" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "async-compression", @@ -8058,7 +8058,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "async-trait", @@ -8092,7 +8092,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript-hmr-protocol" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "serde", "serde_json", @@ -8103,7 +8103,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript-plugins" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "async-trait", @@ -8126,7 +8126,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript-runtime" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "indoc", @@ -8143,7 +8143,7 @@ dependencies = [ [[package]] name = "turbopack-env" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -8159,7 +8159,7 @@ dependencies = [ [[package]] name = "turbopack-image" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "base64 0.21.4", @@ -8179,7 +8179,7 @@ dependencies = [ [[package]] name = "turbopack-json" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "serde", @@ -8194,7 +8194,7 @@ dependencies = [ [[package]] name = "turbopack-mdx" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "mdxjs", @@ -8209,7 +8209,7 @@ dependencies = [ [[package]] name = "turbopack-node" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "async-stream", @@ -8244,7 +8244,7 @@ dependencies = [ [[package]] name = "turbopack-static" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "serde", @@ -8260,7 +8260,7 @@ dependencies = [ [[package]] name = "turbopack-swc-utils" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "swc_core", "turbo-tasks", @@ -8271,7 +8271,7 @@ dependencies = [ [[package]] name = "turbopack-wasm" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231025.1#51b47690aa579b8829b28e18402a28444c301514" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231026.1#dec61ad7505f148fb3f677e1dac9671ebae91550" dependencies = [ "anyhow", "indexmap 1.9.3", diff --git a/Cargo.toml b/Cargo.toml index 1c3820e163ca5..6a68ee69b6bc5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,11 +40,11 @@ swc_core = { version = "0.86.10", features = [ testing = { version = "0.35.0" } # Turbo crates -turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231025.1" } +turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231026.1" } # [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros.. -turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231025.1" } +turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231026.1" } # [TODO]: need to refactor embed_directory! macro usage in next-core -turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231025.1" } +turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231026.1" } # General Deps diff --git a/docs/02-app/01-building-your-application/06-optimizing/10-third-party-libraries.mdx b/docs/02-app/01-building-your-application/06-optimizing/10-third-party-libraries.mdx new file mode 100644 index 0000000000000..e45d6222aa6b0 --- /dev/null +++ b/docs/02-app/01-building-your-application/06-optimizing/10-third-party-libraries.mdx @@ -0,0 +1,288 @@ +--- +title: Third Party Libraries +description: Optimize the performance of third-party libraries in your application with the `@next/third-parties` package. +--- + +{/* The content of this doc is shared between the app and pages router. You can use the `Content` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} + +**`@next/third-parties`** is a library that provides a collection of components and utilities that +improve the performance and developer experience of loading popular third-party libraries in your +Next.js application. + +> **Good to know**: `@next/third-parties` is a new **experimental** library that is still under +> active development. We're currently working on adding more third-party integrations. + +All third-party integrations provided by `@next/third-parties` have been optimized for performance +and ease of use. + +## Getting Started + +To get started, you must install the `@next/third-parties` library: + +```bash filename="Terminal" +npm install @next/third-parties +``` + +## Google Third-Parties + +All supported third-party libraries from Google can be imported from `@next/third-parties/google`. + +### Google Tag Manager + +The `GoogleTagManager` component can be used to instantiate a [Google Tag +Manager](https://developers.google.com/maps/documentation/embed/embedding-map) container to your +page. By default, it fetches the original inline script after hydration occurs on the page. + + + +To load Google Tag Manager for all routes, include the component directly in your root layout: + +```tsx filename="app/layout.tsx" switcher +import { GoogleTagManager } from '@next/third-parties/google' + +export default function RootLayout({ + children, +}: { + children: React.ReactNode +}) { + return ( + + {children} + + + ) +} +``` + +```jsx filename="app/layout.js" switcher +import { GoogleTagManager } from '@next/third-parties/google' + +export default function RootLayout({ children }) { + return ( + + {children} + + + ) +} +``` + + + + + +To load Google Tag Manager for all routes, include the component directly in your custom `_app`: + +```jsx filename="pages/_app.js" +import { GoogleTagManager } from '@next/third-parties/google' + +export default function MyApp({ Component, pageProps }) { + return ( + <> + + + + ) +} +``` + + + +To load Google Tag Manager for a single route, include the comopnent in your page file: + + + +```jsx filename="app/page.js" +import { GoogleTagManager } from '@next/third-parties/google' + +export default function Page() { + return +} +``` + + + + + +```jsx filename="pages/index.js" +import { GoogleTagManager } from '@next/third-parties/google' + +export default function Page() { + return +} +``` + + + +#### Sending Events + +The `sendGTMEvent` function can be used to track user interactions on your page by sending events +using the `dataLayer` object. For this function to work, the `` component must be +included in either a parent layout, page, or component, or directly in the same file. + + + +```jsx filename="app/page.js" +'use client' + +import { sendGTMEvent } from '@next/third-parties/google' + +export function EventButton() { + return ( +
+ +
+ ) +} +``` + +
+ + + +```jsx filename="pages/index.js" +import { sendGTMEvent } from '@next/third-parties/google' + +export function EventButton() { + return ( +
+ +
+ ) +} +``` + +
+ +Refer to the [Tag Manager](https://developers.google.com/tag-platform/tag-manager/datalayer) +documentation to learn about the different variables and events that can be passed into the +function. + +#### Options + +Options to pass to the Google Maps Embed. For a full list of options, read the [Google Map Embed +docs](https://developers.google.com/maps/documentation/embed/embedding-map). + +| Name | Type | Description | +| --------------- | -------- | ------------------------------------------------------------------------------- | +| `gtmId` | Required | Your GTM container id. | +| `dataLayer` | Optional | Data layer array to instantiate the container with. Defaults to an empty array. | +| `dataLayerName` | Optional | Name of the data layer. Defaults to `dataLayer`. | +| `auth` | Optional | Value of authentication parameter (`gtm_auth`) for environment snippets. | +| `preview` | Optional | Value of preview parameter (`gtm_preview`) for environment snippets. | + +### Google Maps Embed + +The `GoogleMapsEmbed` component can be used to add a [Google Maps +Embed](https://developers.google.com/maps/documentation/embed/embedding-map) to your page. By +default, it uses the `loading` attribute to lazy-load the embed below the fold. + + + +```jsx filename="app/page.js" +import { GoogleMapsEmbed } from '@next/third-parties/google' + +export default function Page() { + return ( + + ) +} +``` + + + + + +```jsx filename="pages/index.js" +import { GoogleMapsEmbed } from '@next/third-parties/google' + +export default function Page() { + return ( + + ) +} +``` + + + +#### Options + +Options to pass to the Google Maps Embed. For a full list of options, read the [Google Map Embed +docs](https://developers.google.com/maps/documentation/embed/embedding-map). + +| Name | Type | Description | +| ----------------- | -------- | --------------------------------------------------------------------------------------------------- | +| `apiKey` | Required | Your api key. | +| `mode` | Required | [Map mode](https://developers.google.com/maps/documentation/embed/embedding-map#choosing_map_modes) | +| `height` | Optional | Height of the embed. Defaults to `auto`. | +| `width` | Optional | Width of the embed. Defaults to `auto`. | +| `style` | Optional | Pass styles to the iframe. | +| `allowfullscreen` | Optional | Property to allow certain map parts to go full screen. | +| `loading` | Optional | Defaults to lazy. Consider changing if you know your embed will be above-the-fold. | +| `q` | Optional | Defines map marker location. _This may be required depending on the map mode_. | +| `center` | Optional | Defines center of the map view. | +| `zoom` | Optional | Sets initial zoom level of the map. | +| `maptype` | Optional | Defines type of map tiles to load. | +| `language` | Optional | Defines the language to use for UI elements and for the display of labels on map tiles. | +| `region` | Optional | Defines the appropriate borders and labels to display, based on geo-political sensitivities. | + +### YouTube Embed + +The `YouTubeEmbed` component can be used to load and display a YouTube embed. This component loads +faster by using [`lite-youtube-embed`](https://github.com/paulirish/lite-youtube-embed) under the +hood. + + + +```jsx filename="app/page.js" +import { YouTubeEmbed } from '@next/third-parties/google' + +export default function Page() { + return +} +``` + + + + + +```jsx filename="pages/index.js" +import { YouTubeEmbed } from '@next/third-parties/google' + +export default function Page() { + return +} +``` + + + +#### Options + +| Name | Type | Description | +| ----------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `videoid` | Required | YouTube video id. | +| `width` | Optional | Width of the video container. Defaults to `auto` | +| `height` | Optional | Height of the video container. Defaults to `auto` | +| `playlabel` | Optional | A visually hidden label for the play button for accessibility. | +| `params` | Optional | The video player params defined [here](https://developers.google.com/youtube/player_parameters#Parameters).
Params are passed as a query param string.
Eg: `params="controls=0&start=10&end=30"` | +| `style` | Optional | Used to apply styles to the video container. | diff --git a/docs/03-pages/01-building-your-application/05-optimizing/11-third-party-libraries.mdx b/docs/03-pages/01-building-your-application/05-optimizing/11-third-party-libraries.mdx new file mode 100644 index 0000000000000..0ca3a1ece15dc --- /dev/null +++ b/docs/03-pages/01-building-your-application/05-optimizing/11-third-party-libraries.mdx @@ -0,0 +1,7 @@ +--- +title: Third Party Libraries +description: Optimize the performance of third-party libraries in your application with the `@next/third-parties` package. +source: app/building-your-application/optimizing/third-party-libraries +--- + +{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `Content` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} diff --git a/examples/with-google-tag-manager/.env.local.example b/examples/with-google-tag-manager/.env.local.example deleted file mode 100644 index 474e6beaa7ecb..0000000000000 --- a/examples/with-google-tag-manager/.env.local.example +++ /dev/null @@ -1 +0,0 @@ -NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID= \ No newline at end of file diff --git a/examples/with-google-tag-manager/.gitignore b/examples/with-google-tag-manager/.gitignore deleted file mode 100644 index fd3dbb571a12a..0000000000000 --- a/examples/with-google-tag-manager/.gitignore +++ /dev/null @@ -1,36 +0,0 @@ -# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. - -# dependencies -/node_modules -/.pnp -.pnp.js -.yarn/install-state.gz - -# testing -/coverage - -# next.js -/.next/ -/out/ - -# production -/build - -# misc -.DS_Store -*.pem - -# debug -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# local env files -.env*.local - -# vercel -.vercel - -# typescript -*.tsbuildinfo -next-env.d.ts diff --git a/examples/with-google-tag-manager/README.md b/examples/with-google-tag-manager/README.md deleted file mode 100644 index 1541fec9fd06f..0000000000000 --- a/examples/with-google-tag-manager/README.md +++ /dev/null @@ -1,35 +0,0 @@ -## Example app using Google Tag Manager - -This example shows how to use Next.js along with Google Tag Manager. [`pages/_document.js`](pages/_document.js) is used to inject [base code](https://developers.google.com/tag-manager/quickstart). [`pages/_app.js`](pages/_app.js) is used to track route changes and send page views to Google Tag Manager. - -## Deploy your own - -Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example): - -[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-google-tag-manager&project-name=with-google-tag-manager&repository-name=with-google-tag-manager) - -## How to use - -Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example: - -```bash -npx create-next-app --example with-google-tag-manager with-google-tag-manager-app -``` - -```bash -yarn create next-app --example with-google-tag-manager with-google-tag-manager-app -``` - -```bash -pnpm create next-app --example with-google-tag-manager with-google-tag-manager-app -``` - -Next, copy the `.env.local.example` file in this directory to `.env.local` (which will be ignored by Git): - -```bash -cp .env.local.example .env.local -``` - -Set the `NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID` variable in `.env.local` to match your Google Tag Manager ID. - -Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). diff --git a/examples/with-google-tag-manager/lib/gtm.js b/examples/with-google-tag-manager/lib/gtm.js deleted file mode 100644 index 299c4aa7b8d8c..0000000000000 --- a/examples/with-google-tag-manager/lib/gtm.js +++ /dev/null @@ -1,8 +0,0 @@ -export const GTM_ID = process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID - -export const pageview = (url) => { - window.dataLayer.push({ - event: 'pageview', - page: url, - }) -} diff --git a/examples/with-google-tag-manager/package.json b/examples/with-google-tag-manager/package.json deleted file mode 100644 index 65f904f0513c2..0000000000000 --- a/examples/with-google-tag-manager/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "private": true, - "scripts": { - "dev": "next dev", - "build": "next build", - "start": "next start" - }, - "dependencies": { - "next": "latest", - "react": "^18.2.0", - "react-dom": "^18.2.0" - } -} diff --git a/examples/with-google-tag-manager/pages/_app.js b/examples/with-google-tag-manager/pages/_app.js deleted file mode 100644 index 5481c3d3c97ac..0000000000000 --- a/examples/with-google-tag-manager/pages/_app.js +++ /dev/null @@ -1,36 +0,0 @@ -import { useEffect } from 'react' -import Script from 'next/script' -import { useRouter } from 'next/router' -import { GTM_ID, pageview } from '../lib/gtm' - -function MyApp({ Component, pageProps }) { - const router = useRouter() - useEffect(() => { - router.events.on('routeChangeComplete', pageview) - return () => { - router.events.off('routeChangeComplete', pageview) - } - }, [router.events]) - - return ( - <> - {/* Google Tag Manager - Global base code */} -