Skip to content

Commit 4c35f73

Browse files
authored
fix(tpc): custom feature detection flags (#113)
1 parent 62963b5 commit 4c35f73

File tree

5 files changed

+9
-1
lines changed

5 files changed

+9
-1
lines changed

src/runtime/composables/useScript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function useScript<T extends Record<string | symbol, any>>(input: UseScri
3030
if (!nuxtApp._scripts?.[id]) {
3131
performance?.mark?.('mark_feature_usage', {
3232
detail: {
33-
feature: `nuxt-scripts:${id}`,
33+
feature: options.performanceMarkFeature ?? `nuxt-scripts:${id}`,
3434
},
3535
})
3636
}

src/runtime/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'>
4646
* loading the actual script and not getting warnings.
4747
*/
4848
skipValidation?: boolean
49+
/**
50+
* @internal
51+
*/
52+
performanceMarkFeature?: string
4953
}
5054

5155
export type NuxtUseScriptOptionsSerializable = Omit<NuxtUseScriptOptions, 'use' | 'skipValidation' | 'stub' | 'trigger' | 'eventContext' | 'beforeInit'> & { trigger?: 'client' | 'server' | 'onNuxtReady' }

src/tpc/google-analytics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default function googleAnalitycsRegistry(scripts: RegistryScript[]) {
1919
},
2020
tpcKey: 'gtag',
2121
tpcTypeImport: 'GoogleAnalyticsApi',
22+
featureDetectionName: 'nuxt-third-parties-ga',
2223
})
2324
},
2425
filename: 'nuxt-scripts/tpc/google-analytics.ts',

src/tpc/google-tag-manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default function googleTagManagerRegistry(scripts: RegistryScript[]) {
1919
},
2020
tpcKey: 'gtm',
2121
tpcTypeImport: 'GoogleTagManagerApi',
22+
featureDetectionName: 'nuxt-third-parties-gtm',
2223
})
2324
},
2425
filename: 'nuxt-scripts/tpc/google-tag-manager.ts',

src/tpc/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface ScriptContentOpts {
1717
* This will be stringified. The function must be pure.
1818
*/
1919
stub: (params: { fn: string }) => any
20+
featureDetectionName?: string
2021
}
2122

2223
const HEAD_VAR = '__head'
@@ -100,6 +101,7 @@ ${functionBody.join('\n')}
100101
scriptOptions: {
101102
use: ${input.use.toString()},
102103
stub: import.meta.client ? undefined : ${input.stub.toString()},
104+
${input.featureDetectionName ? `performanceMarkFeature: ${JSON.stringify(input.featureDetectionName)},` : ''}
103105
${mainScriptOptions ? `...(${JSON.stringify(mainScriptOptions)})` : ''}
104106
},
105107
${clientInitCode.length ? `clientInit: import.meta.server ? undefined : () => {${clientInitCode.join('\n')}},` : ''}

0 commit comments

Comments
 (0)