# Third-Party Integrations

> Optimized components for Google Tag Manager, Maps, and YouTube.

Subject: Next.js | Lesson 52 of 65 | 3 min read
Interactive lesson: https://codewithanimation.in/nextjs/third-party-integrations
Previous: [<Script>](https://codewithanimation.in/nextjs/script-optimization.md) | Next: [Static Metadata](https://codewithanimation.in/nextjs/static-metadata.md)

## The @next/third-parties library

Next.js maintains an official library called `@next/third-parties`.

It provides heavily optimized, drop-in React components for the most common third-party integrations, specifically from Google.

## The Iframe Trap

If you copy-paste the standard `<iframe src="https://www.youtube.com/..." />` embed code, the browser will immediately download over 1MB of JavaScript to initialize the YouTube player, even if the user never clicks play.

The Next.js `<YouTubeEmbed />` component uses a technique called a 'facade'. It only downloads a static image thumbnail and a lightweight play button. The heavy player JavaScript is only downloaded when the user actually interacts with it.

## Implementation

1. Install it: `npm install @next/third-parties`

2. Import it: `import { YouTubeEmbed } from '@next/third-parties/google'`

3. Use it: `<YouTubeEmbed videoid="ogfYd705cRs" height={400} params="controls=0" />`

## Common mistake: Lighthouse Killers

Adding just a single standard YouTube iframe or a Google Map embed to a landing page will routinely drop your Lighthouse Performance score by 20 to 30 points.

Always use the Next.js optimized components to preserve your page speed metrics.

## Try it: Iframe vs Optimized Component

Examine the syntax difference between a raw, unoptimized YouTube iframe and the clean, performant Next.js component.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/nextjs/third-party-integrations

## Check yourself

### Question 1

How does the Next.js `<YouTubeEmbed />` component achieve such massive performance gains over a standard `<iframe>`?

- A. It compresses the video using FFmpeg on the edge.
- B. It uses a facade: it only loads a static thumbnail image, delaying the heavy JS player until the user clicks play.
- C. It caches the entire video inside the Next.js Data Cache.
- D. It forces the video to render at 360p resolution.

Correct answer: B

This is called the 'facade' pattern. Instead of loading the entire heavy YouTube player immediately, it just loads a lightweight JPEG thumbnail. When clicked, it swaps the image for the real iframe.

- Why not A: Next.js doesn't touch the video file itself.
- Why not C: You cannot cache gigabytes of video inside Next.js.
- Why not D: Resolution isn't the primary issue; the JavaScript player is.

## Remember this

- Never use raw `<iframe>` tags for YouTube videos or Google Maps.
- Install the `@next/third-parties` package for official Next.js integrations.
- The `<YouTubeEmbed />` component uses a facade to delay loading heavy JavaScript.
- The package also includes optimized components for Google Tag Manager (GTM) and Google Analytics (GA).
