Unverified Commit 3ec0551f authored by Janicklas Ralph's avatar Janicklas Ralph Committed by GitHub

Add performance.mark for next/third-parties for feature measurement (#57439)



### What?

Adding a `performance.mark` for next/third-parties for feature measurement

### Why?

We’re working with the Chrome Speed Metrics team to develop an API to better identify specific features used by frameworks and/or CMS platforms. Instead of a entirely new API surface, we've agreed to use `performance.mark` as the signal along with mark_use_counter as a signature.

In the past, we've used HTML attributes for Next which have been helpful, but this will improve the accuracy of our feature detection. In this instance, this will better help us analyze and compare sites that use `@next/third-parties` versus those that don't, and to see if our efforts are actually improving performance.

It's worth noting that this metric will have a public arm, but we're starting to incorporate its usage now to gather early data. performance.mark calls are indeed low-overhead and shouldn't affect loading/rendering performance whatsoever.
parent 4e5702c1
import React from 'react' 'use client'
import React, { useEffect } from 'react'
export type ScriptEmbed = { export type ScriptEmbed = {
html?: string | null html?: string | null
...@@ -15,6 +17,19 @@ export default function ThirdPartyScriptEmbed({ ...@@ -15,6 +17,19 @@ export default function ThirdPartyScriptEmbed({
children, children,
dataNtpc = '', dataNtpc = '',
}: ScriptEmbed) { }: ScriptEmbed) {
useEffect(() => {
if (dataNtpc) {
// performance.mark is being used as a feature use signal. While it is traditionally used for performance
// benchmarking it is low overhead and thus considered safe to use in production and it is a widely available
// existing API.
performance.mark('mark_feature_usage', {
detail: {
feature: `next-third-parties-${dataNtpc}`,
},
})
}
}, [dataNtpc])
return ( return (
<> <>
{/* insert script children */} {/* insert script children */}
......
'use client' 'use client'
// TODO: Evaluate import 'client only' // TODO: Evaluate import 'client only'
import React from 'react' import React, { useEffect } from 'react'
import Script from 'next/script' import Script from 'next/script'
import type { GTMParams } from '../types/google' import type { GTMParams } from '../types/google'
...@@ -18,6 +18,18 @@ export function GoogleTagManager(props: GTMParams) { ...@@ -18,6 +18,18 @@ export function GoogleTagManager(props: GTMParams) {
const gtmAuth = auth ? `&gtm_auth=${auth}` : '' const gtmAuth = auth ? `&gtm_auth=${auth}` : ''
const gtmPreview = preview ? `&gtm_preview=${preview}&gtm_cookies_win=x` : '' const gtmPreview = preview ? `&gtm_preview=${preview}&gtm_cookies_win=x` : ''
useEffect(() => {
// performance.mark is being used as a feature use signal. While it is traditionally used for performance
// benchmarking it is low overhead and thus considered safe to use in production and it is a widely available
// existing API.
performance.mark('mark_feature_usage', {
detail: {
feature: 'next-third-parties-gtm',
},
})
}, [])
return ( return (
<> <>
<Script <Script
...@@ -33,6 +45,7 @@ export function GoogleTagManager(props: GTMParams) { ...@@ -33,6 +45,7 @@ export function GoogleTagManager(props: GTMParams) {
/> />
<Script <Script
id="_next-gtm" id="_next-gtm"
data-ntpc="GTM"
src={`https://www.googletagmanager.com/gtm.js?id=${gtmId}${gtmLayer}${gtmAuth}${gtmPreview}`} src={`https://www.googletagmanager.com/gtm.js?id=${gtmId}${gtmLayer}${gtmAuth}${gtmPreview}`}
/> />
</> </>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment