Seamlessly integrate v0 with Amplitude using our step‐by‐step guide. Get best practices, tips, and troubleshooting advice for flawless analytics integration.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
index.html).<head> section (or before your main script) to load the Amplitude library from the CDN:
<script src="https://cdn.amplitude.com/libs/amplitude-8.15.0-min.gz.js"></script>
amplitude object is available to your TypeScript code.
src folder) called amplitude.ts.
export class AmplitudeService {
private isAmplitudeLoaded: boolean;
constructor(private apiKey: string) {
// Check if the amplitude global variable exists
this.isAmplitudeLoaded = !!(window as any).amplitude;
if (!this.isAmplitudeLoaded) {
console.error("Amplitude library is not loaded. Verify that you added the script tag in index.html.");
return;
}
// Initialize Amplitude with your API key
(window as any).amplitude.getInstance().init(this.apiKey);
}
trackEvent(eventName: string, eventProperties?: Record<string, any>): void {
if (!this.isAmplitudeLoaded) {
console.error("Amplitude is not loaded. Cannot track event.");
return;
}
(window as any).amplitude.getInstance().logEvent(eventName, eventProperties || {});
}
}
main.ts or similar).
import { AmplitudeService } from "./amplitude";
const AMPLITUDEAPIKEY = "YOURAPIKEY_HERE"; // Replace with your actual API key
const amplitudeService = new AmplitudeService(AMPLITUDEAPIKEY);
// Example usage: Tracking an event called "app_started"
amplitudeService.trackEvent("app_started", { time: new Date().toISOString() });
buttonHandler.ts, add the following code:
import { AmplitudeService } from "./amplitude";
const AMPLITUDEAPIKEY = "YOURAPIKEY_HERE"; // Use the same API key
const amplitudeService = new AmplitudeService(AMPLITUDEAPIKEY);
function onButtonClick() {
// Track a button click event
amplitudeService.trackEvent("button_clicked", { buttonId: "submit-button" });
}
// Assume this function is connected to your button's click event
document.getElementById("submit-button")?.addEventListener("click", onButtonClick);
trackEvent with the relevant event name and details.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.