Sometimes you want to attach additional data to a tracking event beyond just the Affiliate ID. For example, you might want to know exactly which campaign_id or click_id resulted in a sale, or you might want to tie the anonymous click to a specific user_id in your own database once the user signs up.
The Global DMA Object
When you install track.js, it exposes a global window.DMA object on the frontend. You can use this object to send custom metadata to our servers.
Tracking Custom Events
// Example: Sending metadata when a user creates a free account
if (window.DMA) {
window.DMA.identify({
userId: 'usr_98765',
email: 'test@example.com',
plan: 'free_tier'
});
}
By calling identify(), we link the existing affiliate cookie to this specific user ID. If this user upgrades to a paid plan weeks later (and you send a webhook containing their userId or email), we can perfectly attribute the sale to the original affiliate—even if the user clears their cookies!
Using the Backend API
If you are using our Backend API (S2S), you can simply include the metadata object in your POST payload:
await fetch("https://discovermacapps.com/api/affiliate/pixel", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
programId: "YOUR_PROGRAM_ID",
code: "affiliate_123",
metadata: {
source: "newsletter",
campaign: "summer_launch"
}
})
});
This custom metadata will be visible in your Dashboard when you review the specific commission.