RFC: next/third-parties
#48256
Replies: 21 comments 20 replies
-
Thanks for proposing improvements to better handle third-party scripts in NextJS. I think this is definitely a topic that needs better care. On the advertisement side, we can think of
I would have suggested PrebidJS and Adobe Audience Manager script, but usually those are installed locally. Also maybe I know it's just the beginning, hope to follow where this will land 😉 |
Beta Was this translation helpful? Give feedback.
-
Hey! At BlackBox Vision OSS we're developed 2 packages: If this RFC moves, we'd love to contribute by giving the code from our packages directly if possible! And to provide engineers to keep contributing on. |
Beta Was this translation helpful? Give feedback.
-
It is important to keep in mind that the maintenance burden can be significant, and relying on a centralized module for third-party code can create dependencies and potential issues. Overall, this proposal seems like a step in the right direction for managing third-party scripts in Next.js. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if we need this package since we already have Thank you for your contribution. |
Beta Was this translation helpful? Give feedback.
-
I would love to see AdSense added, maybe Plausible (but I know that would conflict with Vercel's acquisition of Splitbee) |
Beta Was this translation helpful? Give feedback.
-
This looks great @housseindjirdeh ! Just curious does it continue to use Next Script element under the hood? |
Beta Was this translation helpful? Give feedback.
-
Throwing in my two cents. Would it make sense to bake this into the // Mock - non existing API
const config = {
poweredByHeader: false,
reactStrictMode: true,
analytics: {
googleAnalytics: true, // or a function which receives the default config, runtime and NODE_ENV?
// or process.env.NEXT_PUBLIC_GA_KEY
},
monitoring: {
someMonitoringAPI: true,
},
};
import { pageview } from 'next/third-party/ga';
// report a page view outside React's tree
pageview('/foo'); Love this initiative, I was a bit taken aback by the GA changes taking place in July, so I moved to the https://github.com/vercel/analytics, and it was a really great DX improvement! |
Beta Was this translation helpful? Give feedback.
-
I do support this idea. There were few instances where I found conflicting information on how to load some of these third party scripts so having an official way these are loaded in the most performant way is great.
Btw, just noticed that these percentage links that go to BigQuery are actually for Nuxt.js, not Next.js. That probably needs to be updated 😄 |
Beta Was this translation helpful? Give feedback.
-
Would supporting user consent to conditionally load libraries make sense for this RFC? Currently, we use GTM to load most of our libraries when the consent events are sent, but hooking it up in the code would most likely be more performant, and allow for loading certain libraries sooner. It should be pretty trivial to conditionally load the libraries on the client with this spec, but having a wrapper around X consent management API events would be a nice addition. |
Beta Was this translation helpful? Give feedback.
-
For folks following this thread, the See the README for some early instructions on how to use it. This package is still early and experimental so please be careful when using in production. However, we would value any feedback if you give it a shot! |
Beta Was this translation helpful? Give feedback.
-
The next two libraries we're currently working on are Google Tag Manager and gtag. We've put some thought into it and realized that providing a component for tag managers and libraries that don't render any content (e.g. Google Analytics) might not be the best approach. I wrote a follow up RFC for this: #53868. Please feel free to drop some feedback! |
Beta Was this translation helpful? Give feedback.
-
Is this package being published? When I attempt to install it I get a |
Beta Was this translation helpful? Give feedback.
-
Is there a proposal to include firebase? If not, can we add that? Since many of us has web n app, we are using firebase analytics to do event tracking in both. Also, other firebase features like remote-config and etc can be used as well. |
Beta Was this translation helpful? Give feedback.
-
If anyone is trying to install the library but is seeing a peerDep error, #57515 fixes it. In the meantime, you can either use the latest |
Beta Was this translation helpful? Give feedback.
-
@housseindjirdeh I think the |
Beta Was this translation helpful? Give feedback.
-
@giannif, @YasielCabrera, @joey-ma and others, if you want to have temporary fix for missing types - then create
Also add such content to your
Where |
Beta Was this translation helpful? Give feedback.
-
I have a problem now. I need to resubmit the Google tracking code GTM for every page, but my current GTM code will only be submitted the first time that the page is re-rendered. The jump within the page uses the Link tag, which causes the page to be preloaded, the page will not be re-rendered, and GTM will not be triggered again. |
Beta Was this translation helpful? Give feedback.
-
The Google maps embed example on the website passes This doesn't work in reality because width is typed as number. export type GoogleMapsEmbed = {
height?: number;
width?: number;
mode: 'place' | 'view' | 'directions' | 'streetview' | 'search';
apiKey: string;
style: string;
allowfullscreen: boolean;
loading: 'eager' | 'lazy';
q?: string;
center?: string;
zoom?: string;
maptype?: string;
language?: string;
region?: string;
}; Even if I ignore the typing and pass |
Beta Was this translation helpful? Give feedback.
-
I have replaced a simple iframe with the Google maps embed component and the amount and timing of JavaScript loaded is exactly the same. The lighthouse scores are also identical. What is the benefit of using the Google maps embed component? |
Beta Was this translation helpful? Give feedback.
-
When is it scheduled to become stable? Can the already added GTM etc. be used stably? |
Beta Was this translation helpful? Give feedback.
-
The GoogleMapsEmbed unfortunately doesn't have the title option which then throws the following accessibility warning: |
Beta Was this translation helpful? Give feedback.
-
Goal
Improve the user and developer experience of loading popular third-party libraries in a Next.js application.
Background
95% of Next.js websites load at least one third-party resource. The
next/script
component currently provides developers with an API that allows them to control when third-party scripts load, but we can make this process simpler for many popular third-party resources by providing pre-configured wrapper components.By providing Next.js developers with a focused set of components, we can:
Proposal
We can provide Next.js developers with a
next/third-parties
package that wraps many popular third-party libraries, improving the developer and user experience of loading and using these libraries.To not increase the install/package size of Next.js, and because it will involve configurations for third-party code — this package can live separate from the core
next
library but remain within the same monorepo.Maintenance
One of the issues of managing third-party code in a centralized module is dealing with the maintenance burden. Maintainers of
next/third-parties
will have to continuously monitor and update underlying loading techniques as the third-parties themselves change and adapt to newer web practices.To solve this, and to prevent duplicating identical loading recommendations for the same third-parties in different places, the Chrome Aurora team is working on Third Party Capital, an NPM library that consolidates best practices for popular third-parties in a single place. For Next.js, we have the option of either relying on this library or creating entirely custom components (or using either of the two approaches depending on the resource itself).
Demo
Here’s a link to a working
next/third-parties
prototype that demonstrates how Third Party Capital could be used under the hood.To summarize how this demo works:
third-party-capital
repothird-party-capital
repo and automatically generates Next.js components for each third-party at build time. Now everytime next/third-parties is version bumped along with its third-party-capital dependency, all third-party components are automatically updated and/or generated with zero maintenance required from the framework side.This prototype is only a rough demonstration of how Third Party Capital can be used to minimize the amount of maintenance required of framework authors and maintainers. This implementation is subject to change.
Selection of Third Parties
For the initial rollout of
next/third-parties
, we suggest supporting a small number of popular third-parties whose performance can be improved by using an alternative method of loading than the general recommended practice. Some examples that have already been included in Third Party Capital:Google Analytics
64% of Next.js sites use Google Analytics. The latest version, which must be used from July 1, 2023 onwards, requires users to fetch an 80 kB gtag.js script. A
<GoogleAnalytics />
component could offload this to a web worker via Partytown or, at the very least, simplify the current developer experience.YouTube Embed
YouTube resources are one of the most popular render-blocking third-parties on the web today. A
<YoutubeEmbed />
component could leverage the techniques used in lite-youtube-embed to load embedded videos significantly faster.Google Maps
8.5% of Next.js sites use Google Maps which is also one of the most popular render-blocking third-parties on the web. A
<GoogleMapsEmbed />
component could automatically include theloading=”lazy”
property to ensure that it is only loaded when it is close to the device viewport.These are only some examples of third-parties that we think developers can benefit from using a framework wrapper but many others will also be considered (for example: Sentry, DataDog, Facebook Pixel).
If you have any suggestions for third-parties you’d like to see included, please leave a comment below!
Beta Was this translation helpful? Give feedback.
All reactions