Nuxt Installation
Installing TrackFox on your Nuxt website is quick and easy. You can use our CLI for automatic installation or manually add the tracking script to your app.
Quick Install with CLI
The fastest way to get started is using the TrackFox CLI:
npx trackfox add
The CLI will automatically detect your Nuxt setup and install the tracking script in the right place. Learn more →
Manual Installation
Step 1: Get Your Tracking Script
- Log in to your TrackFox dashboard
- Click on the website dropdown in the top navigation
- Select "Site Settings" from the dropdown menu
- In the General tab, copy your unique tracking script
Your tracking script will look like this:
<script
defer
src="https://trackfox.app/script.js"
data-website-id="your-website-id-here"
data-domain="yourdomain.com"
></script>
Step 2: Add Script to Your App
For Nuxt 3, you have two options:
Option 1: Using app.vue (Recommended)
If you have an app.vue file in your project root, add the script to the <head>:
<template>
<div>
<NuxtPage />
</div>
</template>
<script setup>
useHead({
script: [
{
defer: true,
src: "https://trackfox.app/script.js",
"data-website-id": "your-website-id-here",
"data-domain": "yourdomain.com",
},
],
});
</script>
Option 2: Using nuxt.config.ts
Alternatively, add the script to your Nuxt config:
// nuxt.config.ts
export default defineNuxtConfig({
app: {
head: {
script: [
{
defer: true,
src: "https://trackfox.app/script.js",
"data-website-id": "your-website-id-here",
"data-domain": "yourdomain.com",
},
],
},
},
});
Step 3: Verify Installation
- Save your changes and restart your Nuxt development server
- Visit your website in a browser
- Return to your TrackFox dashboard
- Use the "Verify Installation" button in Site Settings
- Confirm that page views are being tracked in your dashboard
Custom Event Tracking
Once the base script is installed, you can track custom events:
<script setup>
// Track a custom event
const trackSignup = () => {
window?.trackfox('signup', {
email: 'user@example.com'
})
}
// Track a payment event
const trackPurchase = (amount: number, email: string) => {
window?.trackfox('payment', {
email: email,
amnt: amount // Amount in cents
})
}
</script>
<template>
<button @click="trackSignup">Sign Up</button>
</template>
Environment Variables
Create a .env file with your TrackFox configuration:
NUXT_PUBLIC_TRACKFOX_WEBSITE_ID=your_website_id
NUXT_PUBLIC_TRACKFOX_DOMAIN=your_domain.com
Then use them in your config:
// nuxt.config.ts
export default defineNuxtConfig({
app: {
head: {
script: [
{
defer: true,
src: "https://trackfox.app/script.js",
"data-website-id": process.env.NUXT_PUBLIC_TRACKFOX_WEBSITE_ID,
"data-domain": process.env.NUXT_PUBLIC_TRACKFOX_DOMAIN,
},
],
},
},
});
TypeScript Support
Add type definitions for better TypeScript support:
// types/trackfox.d.ts
declare global {
interface Window {
trackfox: (action: string, ...args: any[]) => void;
}
}
export {};
Testing
Test your installation by:
- Opening your website in a browser
- Checking the Network tab for requests to
trackfox.app - Verifying data appears in your TrackFox dashboard
Troubleshooting
Common issues and solutions:
- Script not loading: Check your website ID and domain configuration
- No data appearing: Ensure the script is loaded before page navigation
- TypeScript errors: Add the type definitions above
Important Notes
Important: Make sure to replace
your-website-id-hereandyourdomain.comwith your actual website ID and domain from the TrackFox dashboard.
Next Steps
Now that you have TrackFox installed on your Nuxt website:
Need help? Contact us for assistance.
Suggest features? We'd love your feedback