Learn how to integrate v0 with TikTok Ads using our step-by-step guide. Enhance your ad campaigns with expert tips and a seamless setup process.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
TikTokAds.ts.export class TikTokAds {
PIXEL_ID: string;
constructor(pixelId: string) {
this.PIXEL_ID = pixelId;
this.initTikTokPixel();
}
private initTikTokPixel(): void {
(function (w: any, d: any, t: any) {
w.TiktokAnalyticsObject = t;
const ttq = w[t] = w[t] || [];
ttq.methods = [
"page", "track", "identify", "instances", "debug", "on", "off",
"once", "ready", "alias", "group", "enable", "disable"
];
ttq.setAndDefer = function (method: string, args: any) {
ttq[method] = function () {
ttq.push([method].concat(Array.prototype.slice.call(arguments, 0)));
};
};
for (let i = 0; i < ttq.methods.length; i++) {
ttq.setAndDefer(ttq.methods[i], []);
}
ttq.instance = function (i: any) {
for (let j = 0; j < ttq.methods.length; j++) {
ttq.setAndDefer(ttq.methods[j], []);
}
return ttq;
};
ttq.load = (pixelId: string) => {
const script = d.createElement("script");
script.type = "text/javascript";
script.async = true;
script.src = https://analytics.tiktok.com/i18n/pixel/events.js?sdkid=${pixelId}&lib=${t};
const firstScript = d.getElementsByTagName("script")[0];
firstScript.parentNode.insertBefore(script, firstScript);
};
// Load the pixel using the provided pixel id
ttq.load(w.TIKTOKPIXELID);
})(window, document, "ttq");
// Trigger the default page view event
(window as any).ttq && (window as any).ttq.page();
}
public trackEvent(eventName: string, eventData?: object): void {
if ((window as any).ttq) {
(window as any).ttq.track(eventName, eventData || {});
}
}
}
main.ts. If you do not have one, create it in your source folder.YOURPIXELID with your actual TikTok Ads Pixel ID.import { TikTokAds } from "./TikTokAds";
// Assign your TikTok Pixel ID to a property on the global window object
(window as any).TIKTOKPIXELID = "YOURPIXELID"; // Replace with your actual pixel ID
// Create an instance of TikTokAds to initialize the pixel
const tiktokAds = new TikTokAds((window as any).TIKTOKPIXELID);
// Example: Tracking a custom event once the DOM is ready
document.addEventListener("DOMContentLoaded", () => {
tiktokAds.trackEvent("CustomEvent", { key: "value" });
});
TikTokAds.ts is saved in your source folder.main.ts) is updated with the provided code snippet so that it imports and initializes the TikTokAds module.
trackEvent method with the appropriate event name and data.YOURPIXELID) with actual values from your TikTok Ads account.When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.