Vue Installation
Installing TrackFox on your Vue website is straightforward. You can use our CLI for automatic installation or manually add the tracking script to your index.html.
Quick Install with CLI
The fastest way to get started is using the TrackFox CLI:
npx trackfox add
The CLI will automatically detect your Vue 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 index.html
Navigate to index.html (or public/index.html for Vue CLI projects) and add the tracking script inside the <head> tag:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vue App</title>
<!-- TrackFox Analytics -->
<script
defer
src="https://trackfox.app/script.js"
data-website-id="your-website-id-here"
data-domain="yourdomain.com"
></script>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
Step 3: Verify Installation
- Save your changes and restart your Vue 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:
Composition API
<script setup lang="ts">
import { ref } from "vue";
const email = ref("");
const trackSignup = () => {
window?.trackfox("signup", {
email: email.value,
});
};
const trackPurchase = (amount: number, userEmail: string) => {
window?.trackfox("payment", {
email: userEmail,
amnt: amount, // Amount in cents
});
};
</script>
<template>
<div>
<input v-model="email" type="email" placeholder="Enter your email" />
<button @click="trackSignup">Sign Up</button>
</div>
</template>
Options API
<script lang="ts">
export default {
data() {
return {
email: "",
};
},
methods: {
trackSignup() {
(window as any)?.trackfox("signup", {
email: this.email,
});
},
trackPurchase(amount: number, email: string) {
(window as any)?.trackfox("payment", {
email: email,
amnt: amount,
});
},
},
};
</script>
<template>
<div>
<input v-model="email" type="email" placeholder="Enter your email" />
<button @click="trackSignup">Sign Up</button>
</div>
</template>
Environment Variables
Create a .env file with your TrackFox configuration:
VITE_TRACKFOX_WEBSITE_ID=your_website_id
VITE_TRACKFOX_DOMAIN=your_domain.com
For Vue CLI projects (older):
VUE_APP_TRACKFOX_WEBSITE_ID=your_website_id
VUE_APP_TRACKFOX_DOMAIN=your_domain.com
Note: Environment variables don't work directly in index.html with Vite. You can either hardcode the values or create a composable:
// src/composables/useTrackFox.ts
export function useTrackFox() {
const trackEvent = (eventName: string, data?: any) => {
window?.trackfox(eventName, data);
};
const trackPayment = (email: string, amount: number) => {
trackEvent("payment", {
email: email,
amnt: amount,
});
};
const trackSignup = (email: string) => {
trackEvent("signup", { email });
};
return {
trackEvent,
trackPayment,
trackSignup,
};
}
TypeScript Support
Add type definitions for better TypeScript support:
// src/env.d.ts
/// <reference types="vite/client" />
declare global {
interface Window {
trackfox: (action: string, ...args: any[]) => void;
}
}
export {};
Vue Router Integration
If you're using Vue Router, the TrackFox script will automatically track route changes. No additional configuration needed!
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
- Environment variables not working: For Vite projects, env vars must start with
VITE_
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 Vue website:
Need help? Contact us for assistance.
Suggest features? We'd love your feedback