Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/runtime/composables/useScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function useScript<T extends Record<string | symbol, any>>(input: UseScri
if (!nuxtApp._scripts?.[id]) {
performance?.mark?.('mark_feature_usage', {
detail: {
feature: `nuxt-scripts:${id}`,
feature: options.performanceMarkFeature ?? `nuxt-scripts:${id}`,
},
})
}
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'>
* loading the actual script and not getting warnings.
*/
skipValidation?: boolean
/**
* @internal
*/
performanceMarkFeature?: string
}

export type NuxtUseScriptOptionsSerializable = Omit<NuxtUseScriptOptions, 'use' | 'skipValidation' | 'stub' | 'trigger' | 'eventContext' | 'beforeInit'> & { trigger?: 'client' | 'server' | 'onNuxtReady' }
Expand Down
1 change: 1 addition & 0 deletions src/tpc/google-analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function googleAnalitycsRegistry() {
},
tpcKey: 'gtag',
tpcTypeImport: 'GoogleAnalyticsApi',
featureDetectionName: 'nuxt-third-parties-ga',
})
},
filename: 'nuxt-scripts/tpc/google-analytics.ts',
Expand Down
1 change: 1 addition & 0 deletions src/tpc/google-tag-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function googleTagManagerRegistry() {
},
tpcKey: 'gtm',
tpcTypeImport: 'GoogleTagManagerApi',
featureDetectionName: 'nuxt-third-parties-gtm',
})
},
filename: 'nuxt-scripts/tpc/google-tag-manager.ts',
Expand Down
2 changes: 2 additions & 0 deletions src/tpc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ScriptContentOpts {
* This will be stringified. The function must be pure.
*/
stub: (params: { fn: string }) => any
featureDetectionName?: string
}

const HEAD_VAR = '__head'
Expand Down Expand Up @@ -94,6 +95,7 @@ ${functionBody.join('\n')}
scriptOptions: {
use: ${input.use.toString()},
stub: import.meta.client ? undefined : ${input.stub.toString()},
${input.featureDetectionName ? `performanceMarkFeature: ${JSON.stringify(input.featureDetectionName)},` : ''}
${mainScriptOptions ? `...(${JSON.stringify(mainScriptOptions)})` : ''}
},
${clientInitCode.length ? `clientInit: import.meta.server ? undefined : () => {${clientInitCode.join('\n')}},` : ''}
Expand Down