Repository navigation
feat: measuremy.site analytics #962
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| --- | ||
| title: measuremy.site | ||
| description: Load the measuremy.site tracker and record custom events. | ||
| links: | ||
| - label: Source | ||
| icon: i-simple-icons-github | ||
| to: https://github.com/nuxt/scripts/blob/main/packages/script/src/runtime/registry/measuremysite-analytics.ts | ||
| size: xs | ||
| --- | ||
|
|
||
| [measuremy.site](https://measuremy.site/) is cookieless web analytics. The tracker is under 1 KB gzipped and stores nothing in the browser. You can read the numbers from the dashboard, or from a coding agent through its [MCP server](https://measuremy.site/docs/mcp). | ||
|
|
||
| The `key` option is the site's public key (`pk_...`) from the Setup tab of the dashboard. It is safe to commit. | ||
|
|
||
| ::script-stats | ||
| :: | ||
|
|
||
| ::script-docs | ||
| :: | ||
|
|
||
| ## Proxying is not supported | ||
|
|
||
| measuremy.site counts unique visitors from a daily salted hash of the connecting IP address and user agent. If your Nuxt server relays beacons, measuremy.site sees the server's IP instead. | ||
|
|
||
| You can bundle the tracker on your Nuxt origin. Beacons still go to `https://a.measuremy.site/collect`: the composable sets `data-api` on the script tag so a bundled copy keeps the endpoint. | ||
|
|
||
| ## Custom events | ||
|
|
||
| Use `proxy.track(name, props)` to record an event. Calls made before the tracker loads run once it is ready. Properties can be strings, numbers or booleans. | ||
|
|
||
| ::code-group | ||
|
|
||
| ```ts [Proxy] | ||
| const { proxy } = useScriptMeasuremysiteAnalytics() | ||
| function trackSignup() { | ||
| proxy.track('signup', { plan: 'pro' }) | ||
| } | ||
| ``` | ||
|
|
||
| ```ts [onLoaded] | ||
| const { onLoaded } = useScriptMeasuremysiteAnalytics() | ||
| onLoaded(({ track }) => { | ||
| track('purchase', { plan: 'annual', amount: 99 }) | ||
| }) | ||
| ``` | ||
|
|
||
| :: | ||
|
|
||
| Clicks and form submits can also be tracked without JavaScript, with a `data-measuremysite-event` attribute on the element. See the [install guide](https://measuremy.site/docs/install). | ||
|
|
||
| ## Page views in Nuxt | ||
|
|
||
| The tracker counts client-side navigation without extra setup. | ||
|
|
||
| ::script-types | ||
| :: | ||
|
|
||
| ## Example | ||
|
|
||
| The default trigger waits until Nuxt is ready: | ||
|
|
||
| ```vue [app.vue] | ||
| <script setup lang="ts"> | ||
| useScriptMeasuremysiteAnalytics({ | ||
| key: 'pk_...', | ||
| }) | ||
| </script> | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import type { RegistryScriptInput } from '#nuxt-scripts/types' | ||
| import { useRegistryScript } from '../utils' | ||
| import { MeasuremysiteAnalyticsOptions } from './schemas' | ||
|
|
||
| export { MeasuremysiteAnalyticsOptions } | ||
|
|
||
| export type MeasuremysiteAnalyticsInput = RegistryScriptInput<typeof MeasuremysiteAnalyticsOptions, false> | ||
|
|
||
| export interface MeasuremysiteAnalyticsApi { | ||
| /** | ||
| * Records a custom event. | ||
| * @param name Event name, e.g. `signup`. | ||
| * @param props Optional properties. Strings, numbers and booleans, up to 2 KB as JSON. | ||
| * @see https://measuremy.site/docs/install | ||
| */ | ||
| track: (name: string, props?: Record<string, string | number | boolean>) => void | ||
| } | ||
|
|
||
| declare global { | ||
| interface Window { | ||
| measuremysite: MeasuremysiteAnalyticsApi | ||
| } | ||
| } | ||
|
|
||
| export function useScriptMeasuremysiteAnalytics<T extends MeasuremysiteAnalyticsApi>(_options?: MeasuremysiteAnalyticsInput) { | ||
| return useRegistryScript<T, typeof MeasuremysiteAnalyticsOptions>('measuremysiteAnalytics', options => ({ | ||
| scriptInput: { | ||
| 'src': 'https://a.measuremy.site/t.js', | ||
| 'data-key': options.key, | ||
| // The tracker posts to /collect on the origin it was served from. | ||
| // Bundling serves it from the Nuxt origin, so the endpoint is pinned here. | ||
| 'data-api': 'https://a.measuremy.site/collect', | ||
| }, | ||
| schema: import.meta.dev ? MeasuremysiteAnalyticsOptions : undefined, | ||
| scriptOptions: { | ||
| use() { | ||
| return window.measuremysite | ||
| }, | ||
| }, | ||
| }), _options) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ function getPlaygroundPath(script: any): string | null { | |
| 'rybbit-analytics': '/third-parties/rybbit-analytics', | ||
| 'pulse-analytics': '/third-parties/pulse-analytics', | ||
| 'statable-analytics': '/third-parties/statable-analytics', | ||
| 'measuremysite-analytics': '/third-parties/measuremysite-analytics', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Map the label that The registry label is 🤖 Prompt for AI Agents |
||
| 'databuddy-analytics': '/third-parties/databuddy-analytics', | ||
| 'umami-analytics': '/third-parties/umami-analytics', | ||
| 'segment': '/third-parties/segment', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: nuxt/scripts
Length of output: 9675
🏁 Script executed:
Repository: nuxt/scripts
Length of output: 33110
🏁 Script executed:
Repository: nuxt/scripts
Length of output: 33833
🏁 Script executed:
Repository: nuxt/scripts
Length of output: 24505
🏁 Script executed:
Repository: nuxt/scripts
Length of output: 32015
🌐 Web query:
official measuremy.site install documentation site verification homepage HTML public key DNS TXT record💡 Result:
Document the DNS verification step.
The default
onNuxtReadytrigger loads the tracker after hydration, sodata-keyis not present in the server-rendered homepage HTML. measuremy.site cannot verify this setup from the homepage. Instruct users to add the DNS TXT record shown in the Setup tab before relying on the dashboard.🐛 Suggested documentation
The default trigger waits until Nuxt is ready: ```vue [app.vue] <script setup lang="ts"> useScriptMeasuremysiteAnalytics({ key: 'pk_...', }) </script>+The default trigger loads the tracker after hydration, so the site key is
+not present in the server-rendered homepage HTML. Add the DNS TXT record
+shown in the measuremy.site Setup tab to verify the site before relying on
+the dashboard.
🤖 Prompt for AI Agents