Skip to content

Commit bc12814

Browse files
committed
chore: clean up
1 parent 6d4773a commit bc12814

File tree

13 files changed

+206
-223
lines changed

13 files changed

+206
-223
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ More coming soon!
8787
[//]: # (TODO | `plausible-analytics` | Plausible Analytics | `usePlausibleAnalytics` |)
8888
[//]: # (TODO | `simple-analytics` | Simple Analytics | `useSimpleAnalytics` |)
8989
[//]: # (TODO | `umami-analytics` | Umami Analytics | `useUmamiAnalytics` |)
90-
[//]: # (TODO | `cloudflare-web-analytics` | Cloudflare Web Analytics | `useCloudflareWebAnalytics` |)
9190
[//]: # (TODO | `matomo` | Matomo | `useMatomo` |)
9291

9392
### Loading Scripts Globally

client/app.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ onDevtoolsClientConnected(async (client) => {
4747
<div>{{ script.key }}</div>
4848
</a>
4949
<div class="opacity-70">
50-
{{ script.$script.status }}
50+
{{ script.$script.status.value }}
5151
</div>
5252
<div v-if="scriptSizes[script.key]">
5353
{{ scriptSizes[script.key] }}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,16 @@
4747
"build": {
4848
"externals": [
4949
"@unhead/vue",
50-
"@unhead/schema"
50+
"@unhead/schema",
51+
"@unhead/vue",
52+
"#nuxt-scripts"
5153
]
5254
},
5355
"dependencies": {
5456
"@nuxt/devtools-kit": "^1.1.5",
5557
"@nuxt/devtools-ui-kit": "^1.1.5",
5658
"@nuxt/kit": "^3.11.1",
59+
"@unhead/vue": "^1.9.3",
5760
"consola": "^3.2.3",
5861
"defu": "^6.1.4",
5962
"estree-walker": "^3.0.3",

playground/app.vue

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,3 @@
1-
<script lang="ts" setup>
2-
import { ref, useAnalyticsPageEvent, useScript } from '#imports'
3-
import { scriptConsent } from '~/composables/consent'
4-
5-
interface GenericTrackingScript {
6-
track: (title: string, path: string) => void
7-
}
8-
9-
const { track } = useScript<GenericTrackingScript>('https://example.com/script.js?nuxt-scripts=inline', {
10-
trigger: scriptConsent,
11-
})
12-
useAnalyticsPageEvent((payload) => {
13-
track(payload)
14-
})
15-
16-
const showCookieBanner = ref(true)
17-
18-
function acceptCookies() {
19-
scriptConsent.accept()
20-
showCookieBanner.value = false
21-
}
22-
</script>
23-
241
<template>
252
<div class="flex flex-col min-h-screen">
263
<header class="sticky top-0 z-50 w-full backdrop-blur flex-none border-b border-gray-900/10 dark:border-gray-50/[0.06] bg-white/75 dark:bg-gray-900/75">
@@ -47,18 +24,5 @@ function acceptCookies() {
4724
</div>
4825
</UContainer>
4926
</main>
50-
<div v-if="showCookieBanner" id="cookie-consent" class="p-5 bg-blue-900">
51-
<div class="font-bold mb-2">
52-
Do you accept cookies?
53-
</div>
54-
<div class="flex items-center gap-4">
55-
<UButton @click="acceptCookies">
56-
Yes
57-
</UButton>
58-
<UButton @click="showCookieBanner = false">
59-
No
60-
</UButton>
61-
</div>
62-
</div>
6327
</div>
6428
</template>

playground/composables/consent.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

playground/nuxt.config.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ export default defineNuxtConfig({
66
],
77
devtools: { enabled: true },
88
scripts: {
9-
globals: [
10-
'https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.global.prod.js',
11-
],
12-
overrides: {
13-
'cloudflare-turnstile': {
14-
assetStrategy: 'bundle',
15-
},
16-
},
9+
// TODO globals / register / overrides
1710
},
1811
})
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script lang="ts" setup>
2+
import { ref } from 'vue'
3+
import { createScriptConsentTrigger, useScript } from '#imports'
4+
5+
const showCookieBanner = ref(true)
6+
const scriptConsent = createScriptConsentTrigger()
7+
function acceptCookies() {
8+
scriptConsent.accept()
9+
showCookieBanner.value = false
10+
}
11+
useScript('https://www.googletagmanager.com/gtag/js?id=GTM-5ZQZJZ', {
12+
trigger: scriptConsent,
13+
assetStrategy: 'bundle',
14+
})
15+
</script>
16+
17+
<template>
18+
<div v-if="showCookieBanner" id="cookie-consent" class="p-5 bg-blue-900">
19+
<div class="font-bold mb-2">
20+
Do you accept cookies?
21+
</div>
22+
<div class="flex items-center gap-4">
23+
<UButton @click="acceptCookies">
24+
Yes
25+
</UButton>
26+
<UButton @click="showCookieBanner = false">
27+
No
28+
</UButton>
29+
</div>
30+
</div>
31+
</template>

playground/pages/index.vue

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ const thirdParties = [
3131
path: '/third-parties/segment',
3232
},
3333
]
34+
35+
const features = [
36+
{
37+
name: 'Cookie Consent',
38+
path: '/features/cookie-consent',
39+
},
40+
{
41+
name: 'Trigger: On Nuxt Ready',
42+
path: '/features/on-nuxt-ready',
43+
},
44+
]
3445
</script>
3546

3647
<template>
@@ -54,6 +65,24 @@ const thirdParties = [
5465
</div>
5566
</div>
5667
</div>
68+
<div>
69+
<h2 class="font-bold mb-5 text-xl flex items-center">
70+
<Icon
71+
name="carbon:intent-request-create"
72+
class="opacity-70 mr-2"
73+
/>Features
74+
</h2>
75+
<div class="grid grid-cols-3 gap-5">
76+
<div v-for="(s, key) in features" :key>
77+
<ULink
78+
:to="s.path"
79+
class="underline"
80+
>
81+
{{ s.name }}
82+
</ULink>
83+
</div>
84+
</div>
85+
</div>
5786
</div>
5887
</div>
5988
</template>

playground/pages/third-parties/fathom-analytics.vue

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,27 @@ useHead({
66
})
77
88
// composables return the underlying api as a proxy object and a $script with the script state
9-
const { $script, trackPageview, trackGoal } = useScriptFathomAnalytics({
9+
const { $script, trackPageview, trackEvent } = useScriptFathomAnalytics({
1010
site: 'BRDEJWKJ',
11-
// load after 3 seconds
12-
trigger: new Promise<void>((resolve) => {
13-
setTimeout(() => {
14-
resolve()
15-
}, 2000)
16-
}),
1711
})
1812
// this will be triggered once the script is ready async
1913
trackPageview({ url: '/fathom' })
20-
// we can manually wait for the script to be ready (TODO error handling)
21-
$script.then(() => {
22-
// eslint-disable-next-line no-console
23-
console.log('fathom is ready')
24-
})
25-
//
14+
2615
const clicks = ref(0)
27-
async function trackEvent() {
16+
async function clickHandler() {
2817
clicks.value++
29-
trackGoal('button', clicks.value)
18+
trackEvent('ClickedButton', { _value: clicks.value })
3019
}
3120
</script>
3221

3322
<template>
3423
<div>
35-
<UButton @click="trackEvent">
24+
<UButton @click="clickHandler">
3625
important conversion {{ clicks }}
3726
</UButton>
3827
<ClientOnly>
3928
<div>
40-
status: {{ $script.status }}
29+
status: {{ $script.status.value }}
4130
</div>
4231
</ClientOnly>
4332
</div>

playground/pages/third-parties/segment.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const { $script } = useScriptSegment({ writeKey: 'KBXOGxgqMFjm2mxtJDJg0iDn5AnGYb
1313
<div>
1414
<ClientOnly>
1515
<div>
16-
status: {{ $script.status }}
16+
status: {{ $script.status.value }}
1717
</div>
1818
</ClientOnly>
1919
</div>

playground/pages/tracking.vue

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)