Angular Installation
Installing TrackFox on your Angular 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 Angular 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 src/index.html and add the tracking script inside the <head> tag:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Your Angular App</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<!-- TrackFox Analytics -->
<script
defer
src="https://trackfox.app/script.js"
data-website-id="your-website-id-here"
data-domain="yourdomain.com"
></script>
</head>
<body>
<app-root></app-root>
</body>
</html>
Step 3: Verify Installation
- Save your changes and restart your Angular 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:
import { Component } from "@angular/core";
@Component({
selector: "app-signup",
templateUrl: "./signup.component.html",
})
export class SignupComponent {
trackSignup(): void {
(window as any)?.trackfox("signup", {
email: "user@example.com",
});
}
trackPurchase(amount: number, email: string): void {
(window as any)?.trackfox("payment", {
email: email,
amnt: amount, // Amount in cents
});
}
}
Environment Variables
Add your TrackFox configuration to src/environments/environment.ts:
export const environment = {
production: false,
trackfox: {
websiteId: "your_website_id",
domain: "your_domain.com",
},
};
And for production in src/environments/environment.prod.ts:
export const environment = {
production: true,
trackfox: {
websiteId: "your_website_id",
domain: "your_domain.com",
},
};
Then use them in your index.html or create a service:
// src/app/services/analytics.service.ts
import { Injectable } from "@angular/core";
import { environment } from "../../environments/environment";
declare global {
interface Window {
trackfox: (action: string, ...args: any[]) => void;
}
}
@Injectable({
providedIn: "root",
})
export class AnalyticsService {
trackEvent(eventName: string, data?: any): void {
if (typeof window !== "undefined" && window.trackfox) {
window.trackfox(eventName, data);
}
}
trackPayment(email: string, amount: number): void {
this.trackEvent("payment", {
email: email,
amnt: amount, // Amount in cents
});
}
trackSignup(email: string): void {
this.trackEvent("signup", { email });
}
}
TypeScript Support
Add type definitions for better TypeScript support:
// src/types/window.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 Angular website:
Need help? Contact us for assistance.
Suggest features? We'd love your feedback