Skip to content

Commit 798ddcb

Browse files
authored
fix(tpc): update TPC and fix GA (#186)
1 parent debf873 commit 798ddcb

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"shiki": "^1.10.3",
9090
"sirv": "^2.0.4",
9191
"std-env": "^3.7.0",
92-
"third-party-capital": "^2.1.1",
92+
"third-party-capital": "2.3.0",
9393
"ufo": "^1.5.3",
9494
"unimport": "^3.7.2",
9595
"unplugin": "^1.11.0",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/generateTpcScripts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const scripts: Array<TpcDescriptor> = [
4545
key: 'googleAnalytics',
4646
tpcTypesImport: ['DataLayer', 'GTag'],
4747
performanceMarkFeature: 'nuxt-third-parties-ga',
48-
useBody: 'const gtag: GTag = function (...args:Parameters<GTag>) { \n((window as any)[options.l ?? "dataLayer"] as DataLayer).push(args);} as GTag\nreturn { dataLayer: (window as any)[options.l ?? "dataLayer"] as DataLayer,\n gtag }',
48+
useBody: 'const gtag: GTag = function (...args:Parameters<GTag>) { \n((window as any)["gtag-"+(options.l ?? "dataLayer")] as GTag)(...args);} as GTag\nreturn { dataLayer: (window as any)[options.l ?? "dataLayer"] as DataLayer,\n gtag }',
4949
// allow dataLayer to be accessed on the server
5050
returnStub: 'fn === \'dataLayer\' ? [] : void 0',
5151
}]

scripts/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ ${functionBody.join('\n')}
132132

133133
function replaceTokenToRuntime(code: string, defaultValues?: Record<string, string | number | undefined>) {
134134
return code.split(';').map(c => c.replaceAll(/'?\{\{(.*?)\}\}'?/g, (_, token) => {
135-
return `options?.${token} ${defaultValues?.[token] ? `?? ${JSON.stringify(defaultValues?.[token])}` : ''}`
135+
return `(options?.${token} ${defaultValues?.[token] ? `?? ${JSON.stringify(defaultValues?.[token])}` : ''})`
136136
})).join(';')
137137
}
138138

src/runtime/registry/google-analytics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type GoogleAnalyticsInput = RegistryScriptInput<typeof GoogleAnalyticsOpt
1313

1414
function use(options: GoogleAnalyticsInput) {
1515
const gtag: GTag = function (...args: Parameters<GTag>) {
16-
((window as any)[options.l ?? 'dataLayer'] as DataLayer).push(args)
16+
((window as any)['gtag-' + (options.l ?? 'dataLayer')] as GTag)(...args)
1717
} as GTag
1818
return { dataLayer: (window as any)[options.l ?? 'dataLayer'] as DataLayer,
1919
gtag }
@@ -34,6 +34,6 @@ export function useScriptGoogleAnalytics(_options?: GoogleAnalyticsInput) {
3434
// eslint-disable-next-line
3535
// @ts-ignore
3636
// eslint-disable-next-line
37-
clientInit: import.meta.server ? undefined : () => {window[options?.l ?? "dataLayer"]=window[options?.l ?? "dataLayer"]||[];window[options?.l ?? "dataLayer"].push({'js':new Date()});window[options?.l ?? "dataLayer"].push({'config':options?.id })},
37+
clientInit: import.meta.server ? undefined : () => {window[(options?.l ?? "dataLayer")]=window[(options?.l ?? "dataLayer")]||[];window['gtag-'+(options?.l ?? "dataLayer")]=function (){window[(options?.l ?? "dataLayer")].push(arguments);};window['gtag-'+(options?.l ?? "dataLayer")]('js',new Date());window['gtag-'+(options?.l ?? "dataLayer")]('config',(options?.id ))},
3838
}), _options)
3939
}

src/runtime/registry/google-tag-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ export function useScriptGoogleTagManager(_options?: GoogleTagManagerInput) {
3333
// eslint-disable-next-line
3434
// @ts-ignore
3535
// eslint-disable-next-line
36-
clientInit: import.meta.server ? undefined : () => {window[options?.l ?? "dataLayer"]=window[options?.l ?? "dataLayer"]||[];window[options?.l ?? "dataLayer"].push({'gtm.start':new Date().getTime(),event:'gtm.js'});},
36+
clientInit: import.meta.server ? undefined : () => {window[(options?.l ?? "dataLayer")]=window[(options?.l ?? "dataLayer")]||[];window[(options?.l ?? "dataLayer")].push({'gtm.start':new Date().getTime(),event:'gtm.js'});},
3737
}), _options)
3838
}

0 commit comments

Comments
 (0)