JavaScript API
The attribu.tech pixel exposes window.attribu() for programmatic event tracking.
Methods
Custom event
window.attribu(eventName: string, data?: object, callback?: function)Send a custom event with optional data.
window.attribu("signup", { plan: "pro", source: "homepage" });Identify
window.attribu("identify", {
user_id: string, // required
email?: string,
name?: string,
...extraData
})Link the current visitor to a known user. Call this after login or signup.
window.attribu("identify", {
user_id: "usr_abc123",
email: "jane@example.com",
name: "Jane Doe",
});Payment
window.attribu("payment", { email: string })Manually record a payment event. Use this if you're not using Stripe Checkout and need client-side payment tracking.
window.attribu("payment", { email: "customer@example.com" });Event queue
To send events before the script loads, set up a queue:
<script>
window.attribu = window.attribu || function() {
(window.attribu.q = window.attribu.q || []).push(arguments);
};
</script>Events queued this way are automatically replayed when the pixel loads.
Reading visitor ID
To read the current visitor ID from cookies:
function getCookie(name) {
const match = document.cookie.match(
new RegExp("(^| )" + name + "=([^;]+)")
);
return match ? match[2] : null;
}
const visitorId = getCookie("attribu_visitor_id");
const sessionId = getCookie("attribu_session_id");Callback
All methods accept an optional callback that fires when the event is sent:
window.attribu("cta_clicked", { button: "hero" }, (result) => {
console.log("Event sent, status:", result.status);
});