Skip to content

Commit b20a531

Browse files
committedFeb 7, 2025·
Merge remote-tracking branch 'origin/main'
2 parents f545526 + e2eb948 commit b20a531

File tree

7 files changed

+55
-251
lines changed

7 files changed

+55
-251
lines changed
 

‎.github/workflows/ci.yml

+9-5
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v4
18-
- run: corepack enable
19-
- uses: actions/setup-node@v4
18+
- uses: pnpm/action-setup@v4
19+
name: Install pnpm
2020
with:
21-
node-version: 18
22-
cache: pnpm
21+
version: 9.15.2
22+
run_install: false
23+
- name: Install Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: 22
27+
cache: 'pnpm'
2328
- run: pnpm install
24-
2529
# https://github.com/vitejs/vite/blob/main/.github/workflows/ci.yml#L62
2630
# Install playwright's binary under custom directory to cache
2731
- name: Set Playwright path (non-windows)

‎package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@
4949
"lint:fix": "eslint . --fix",
5050
"test": "pnpm dev:prepare && vitest --run --exclude **/__runtime__ && pnpm test:runtime",
5151
"test:runtime": "cd test/fixtures/basic && vitest --run",
52-
"test:types": "echo 'broken due to type regeneration, use pnpm typecheck' && npx nuxi typecheck",
53-
"script:generate-tpc": "bun ./scripts/generateTpcScripts.ts && pnpm lint:fix"
52+
"test:types": "echo 'broken due to type regeneration, use pnpm typecheck' && npx nuxi typecheck"
5453
},
5554
"build": {
5655
"externals": [

‎scripts/generateTpcScripts.ts

-61
This file was deleted.

‎scripts/tsconfig.json

-6
This file was deleted.

‎scripts/utils.ts

-150
This file was deleted.
+32-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// WARNING: This file is automatically generated, do not manually modify.
21
import { withQuery } from 'ufo'
32
import type { DataLayer, GTag } from 'third-party-capital'
43
import { useRegistryScript } from '#nuxt-scripts/utils'
@@ -9,31 +8,49 @@ export const GoogleAnalyticsOptions = object({
98
id: string(),
109
l: optional(string()),
1110
})
11+
1212
export type GoogleAnalyticsInput = RegistryScriptInput<typeof GoogleAnalyticsOptions>
1313

14-
function use(options: GoogleAnalyticsInput) {
15-
const gtag: GTag = function (...args: Parameters<GTag>) {
16-
((window as any)['gtag-' + (options.l ?? 'dataLayer')] as GTag)(...args)
17-
} as GTag
18-
return { dataLayer: (window as any)[options.l ?? 'dataLayer'] as DataLayer,
19-
gtag }
14+
export interface GoogleAnalyticsApi {
15+
gtag: GTag
16+
dataLayer: DataLayer
2017
}
2118

22-
export function useScriptGoogleAnalytics(_options?: GoogleAnalyticsInput) {
23-
return useRegistryScript<ReturnType<typeof use>, typeof GoogleAnalyticsOptions>(_options?.key || 'googleAnalytics', options => ({
19+
export function useScriptGoogleAnalytics<T extends GoogleAnalyticsApi>(_options?: GoogleAnalyticsInput) {
20+
return useRegistryScript<T, typeof GoogleAnalyticsOptions>(_options?.key || 'googleAnalytics', options => ({
2421
scriptInput: {
2522
src: withQuery('https://www.googletagmanager.com/gtag/js', { id: options?.id, l: options?.l }),
2623
},
2724
schema: import.meta.dev ? GoogleAnalyticsOptions : undefined,
2825
scriptOptions: {
29-
use: () => use(options),
26+
use: () => {
27+
const gtag: GTag = function (...args: Parameters<GTag>) {
28+
((window as any)['gtag-' + (options.l ?? 'dataLayer')] as GTag)(...args)
29+
} as GTag
30+
return {
31+
dataLayer: (window as any)[options.l ?? 'dataLayer'] as DataLayer,
32+
gtag,
33+
}
34+
},
3035
stub: import.meta.client ? undefined : ({ fn }) => { return fn === 'dataLayer' ? [] : void 0 },
3136
performanceMarkFeature: 'nuxt-third-parties-ga',
32-
...({ tagPriority: 1 }),
37+
tagPriority: 1,
3338
},
34-
// eslint-disable-next-line
35-
// @ts-ignore
36-
// eslint-disable-next-line
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 ))},
39+
clientInit: import.meta.server
40+
? undefined
41+
: () => {
42+
const dataLayerName = options?.l ?? 'dataLayer'
43+
const dataLayer = (window as any)[dataLayerName] || [];
44+
45+
(window as any)[dataLayerName] = dataLayer
46+
// eslint-disable-next-line
47+
// @ts-ignore
48+
window['gtag-' + (dataLayerName)] = function () {
49+
// eslint-disable-next-line
50+
(window as any)[dataLayerName].push(arguments)
51+
}
52+
; ((window as any)['gtag-' + (dataLayerName)] as GTag)('js', new Date())
53+
; ((window as any)['gtag-' + (dataLayerName)] as GTag)('config', (options?.id))
54+
},
3855
}), _options)
3956
}
+13-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// WARNING: This file is automatically generated, do not manually modify.
21
import { withQuery } from 'ufo'
32
import type { GoogleTagManagerApi, DataLayer } from 'third-party-capital'
43
import { useRegistryScript } from '#nuxt-scripts/utils'
@@ -12,27 +11,29 @@ export const GoogleTagManagerOptions = object({
1211
id: string(),
1312
l: optional(string()),
1413
})
15-
export type GoogleTagManagerInput = RegistryScriptInput<typeof GoogleTagManagerOptions>
1614

17-
function use(options: GoogleTagManagerInput) {
18-
return { dataLayer: (window as any)[options.l ?? 'dataLayer'] as DataLayer, google_tag_manager: window.google_tag_manager }
19-
}
15+
export type GoogleTagManagerInput = RegistryScriptInput<typeof GoogleTagManagerOptions>
2016

21-
export function useScriptGoogleTagManager(_options?: GoogleTagManagerInput) {
22-
return useRegistryScript<ReturnType<typeof use>, typeof GoogleTagManagerOptions>(_options?.key || 'googleTagManager', options => ({
17+
export function useScriptGoogleTagManager<T extends GoogleTagManagerApi>(_options?: GoogleTagManagerInput) {
18+
return useRegistryScript<T, typeof GoogleTagManagerOptions>(_options?.key || 'googleTagManager', options => ({
2319
scriptInput: {
2420
src: withQuery('https://www.googletagmanager.com/gtm.js', { id: options?.id, l: options?.l }),
2521
},
2622
schema: import.meta.dev ? GoogleTagManagerOptions : undefined,
2723
scriptOptions: {
28-
use: () => use(options),
24+
use: () => {
25+
return { dataLayer: (window as any)[options.l ?? 'dataLayer'] as DataLayer, google_tag_manager: window.google_tag_manager }
26+
},
2927
stub: import.meta.client ? undefined : ({ fn }) => { return fn === 'dataLayer' ? [] : void 0 },
3028
performanceMarkFeature: 'nuxt-third-parties-gtm',
3129
...({ tagPriority: 1 }),
3230
},
33-
// eslint-disable-next-line
34-
// @ts-ignore
35-
// 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'});},
31+
clientInit: import.meta.server
32+
? undefined
33+
: () => {
34+
const dataLayerName = options?.l ?? 'dataLayer';
35+
(window as any)[dataLayerName] = (window as any)[(options?.l ?? 'dataLayer')] || []
36+
;(window as any)[dataLayerName].push({ 'gtm.start': new Date().getTime(), 'event': 'gtm.js' })
37+
},
3738
}), _options)
3839
}

0 commit comments

Comments
 (0)
Please sign in to comment.