The examples below cover all three API operations you need to integrate ENS Ads: fetching campaigns, recording impressions, and recording clicks. Each section shows both JavaScript and Python implementations side by side so you can drop the relevant code directly into your server-side integration.
Store your API key in an environment variable (for example, process.env.ENS_API_KEY in Node.js or os.environ["ENS_API_KEY"] in Python) rather than hardcoding it in your source code. This keeps the key out of version control and makes it easier to rotate without a code change.
Fetch campaigns
Call this when you need to retrieve available campaigns for a specific placement. Pass location and device to target campaigns to your user’s context.
Track impression
Call this immediately after a campaign becomes visible to the user. Use the id field from the fetched campaign object as campaignId.
Track click
Call this when the user clicks or otherwise interacts with the campaign. Pass the same campaignId, placement, location, and device values you used for the impression call.