-
Notifications
You must be signed in to change notification settings - Fork 68
feat(tpc): build-time third-party-capital composables #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
cbf1619
feat: wip
huang-julien 2832a38
working poc for gtag + disable #77 bug in playground
huang-julien f3691b6
various fixes
huang-julien c27c65b
feat: handle link and additionnal scripts
huang-julien 65a9f56
Merge branch 'main' into feat/poc_build_time_tpc
julien-huang-leetchi f5f90af
refactor: replace registry and various changes
huang-julien 97cecbf
chore: lint
huang-julien be8066d
chore: update tpc and move it to peer deps
huang-julien f78ef09
refactor: directly use json Data from tpc
huang-julien 2d9d9cb
chore: lint
huang-julien 106ecc4
fix: forgot to trigger functions
huang-julien 278eddb
build: add missing external
huang-julien 6084daf
fix: types and tpye imports
huang-julien 4e087be
chore: inc tpc version
huang-julien e8d1355
chore: update lockfile
huang-julien e5014de
chore: remove old registry and composables
huang-julien 6da9638
fix: imports
huang-julien 798c807
test: test transformation
huang-julien b395827
refactor: move generated composables to nuxt-script build dir
huang-julien 7e724f9
chore: remove commented import
huang-julien 263a7fc
fix: feedbacks
huang-julien 14592fc
test: update snapshots
huang-julien 3cc3e34
fix: imports
huang-julien a33b089
oops
huang-julien 0045e68
test: update snapshot
huang-julien a951aa9
chore: move tpc to dependencies
julien-huang-leetchi fe5a133
Merge remote-tracking branch 'origin/main' into feat/poc_build_time_tpc
julien-huang-leetchi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { addImports, addTemplate, useNuxt } from '@nuxt/kit' | ||
import type { Output } from 'third-party-capital' | ||
import { GooglaAnalyticsData, GoogleAnalytics } from 'third-party-capital' | ||
import type { RegistryScript } from '../runtime/types' | ||
import { getTpcScriptContent } from './utils' | ||
|
||
export default function googleAnalitycsRegistry() { | ||
const nuxt = useNuxt() | ||
const { dst } = addTemplate({ | ||
getContents() { | ||
return getTpcScriptContent({ | ||
data: GooglaAnalyticsData as Output, | ||
scriptFunctionName: 'useScriptGoogleAnalytics', | ||
use: () => { | ||
return { dataLayer: window.dataLayer, gtag: window.gtag } | ||
}, | ||
// allow dataLayer to be accessed on the server | ||
stub: ({ fn }) => { | ||
return fn === 'dataLayer' ? [] : undefined | ||
}, | ||
tpcKey: 'gtag', | ||
tpcTypeImport: 'GoogleAnalyticsApi', | ||
augmentWindowTypes: true, | ||
}) | ||
}, | ||
filename: 'nuxt-scripts/tpc/google-analytics.ts', | ||
}) | ||
|
||
addImports({ | ||
from: dst, | ||
name: 'useScriptGoogleAnalytics', | ||
}) | ||
const registry: RegistryScript = { | ||
label: 'Google Tag Manager', | ||
category: 'tracking', | ||
logo: `<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 256 256"><path fill="#8AB4F8" d="m150.262 245.516l-44.437-43.331l95.433-97.454l46.007 45.091z"/><path fill="#4285F4" d="M150.45 53.938L106.176 8.731L9.36 104.629c-12.48 12.48-12.48 32.713 0 45.207l95.36 95.986l45.09-42.182l-72.654-76.407z"/><path fill="#8AB4F8" d="m246.625 105.37l-96-96c-12.494-12.494-32.756-12.494-45.25 0c-12.495 12.495-12.495 32.757 0 45.252l96 96c12.494 12.494 32.756 12.494 45.25 0c12.495-12.495 12.495-32.757 0-45.251"/><circle cx="127.265" cy="224.731" r="31.273" fill="#246FDB"/></svg>`, | ||
import: { | ||
name: 'useScriptGoogleAnalytics', | ||
from: dst, | ||
}, | ||
scriptBundling(options) { | ||
const data = GoogleAnalytics(options) | ||
const mainScript = data.scripts?.find(({ key }) => key === 'gtag') | ||
|
||
if (mainScript && 'url' in mainScript && mainScript.url) | ||
return mainScript.url | ||
|
||
return false | ||
}, | ||
} | ||
nuxt.hook('scripts:registry', (scripts) => { | ||
scripts.push(registry) | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { addImports, addTemplate, useNuxt } from '@nuxt/kit' | ||
import type { Output } from 'third-party-capital' | ||
import { GoogleTagManager, GoogleTagManagerData } from 'third-party-capital' | ||
|
||
import type { RegistryScript } from '../runtime/types' | ||
import { getTpcScriptContent } from './utils' | ||
|
||
export default function googleTagManagerRegistry() { | ||
const nuxt = useNuxt() | ||
|
||
const { dst } = addTemplate({ | ||
getContents() { | ||
return getTpcScriptContent({ | ||
data: GoogleTagManagerData as Output, | ||
scriptFunctionName: 'useScriptGoogleTagManager', | ||
use: () => { | ||
return { dataLayer: window.dataLayer, google_tag_manager: window.google_tag_manager } | ||
}, | ||
stub: ({ fn }) => { | ||
return fn === 'dataLayer' ? [] : undefined | ||
}, | ||
tpcKey: 'gtm', | ||
tpcTypeImport: 'GoogleTagManagerApi', | ||
augmentWindowTypes: true, | ||
}) | ||
}, | ||
filename: 'nuxt-scripts/tpc/google-tag-manager.ts', | ||
}) | ||
|
||
addImports({ | ||
from: dst, | ||
name: 'useScriptGoogleTagManager', | ||
}) | ||
|
||
const registry: RegistryScript = { | ||
label: 'Google Tag Manager', | ||
category: 'tracking', | ||
logo: `<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 256 256"><path fill="#8AB4F8" d="m150.262 245.516l-44.437-43.331l95.433-97.454l46.007 45.091z"/><path fill="#4285F4" d="M150.45 53.938L106.176 8.731L9.36 104.629c-12.48 12.48-12.48 32.713 0 45.207l95.36 95.986l45.09-42.182l-72.654-76.407z"/><path fill="#8AB4F8" d="m246.625 105.37l-96-96c-12.494-12.494-32.756-12.494-45.25 0c-12.495 12.495-12.495 32.757 0 45.252l96 96c12.494 12.494 32.756 12.494 45.25 0c12.495-12.495 12.495-32.757 0-45.251"/><circle cx="127.265" cy="224.731" r="31.273" fill="#246FDB"/></svg>`, | ||
import: { | ||
name: 'useScriptGoogleTagManager', | ||
from: dst, | ||
}, | ||
scriptBundling(options) { | ||
const data = GoogleTagManager(options) | ||
const mainScript = data.scripts?.find(({ key }) => key === 'gtm') | ||
|
||
if (mainScript && 'url' in mainScript && mainScript.url) | ||
return mainScript.url | ||
|
||
return false | ||
}, | ||
} | ||
|
||
nuxt.hook('scripts:registry', (scripts) => { | ||
scripts.push(registry) | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.