Custom API campaigns let you use the power of Dynamic Yield A/B testing and automatic allocation, while fully controlling how the campaigns are rendered on your site. Variations of your custom API campaigns are JSON files, so each call results in a JSON that you can use to render an element on your site.
Creating server-side API custom campaigns
Step 1: Create the campaign
- In Web Personalization, click Create Campaign.
- Select API Custom Code.
- Enter a name, and add notes and labels (optional).
- Specify the API Selector. This selector is needed in API calls to the campaign.
- Optionally, specify a selector group. Learn more about selector groups.
- Optionally, in the Advanced Settings, you can select to serve multiple variations per decision (say, for carousel or grid variations).
- Click Next.
Step 2: Create variations
- In the Experience screen, name your experience, and select to create a new variation or copy an existing variation. You can also choose to manage your experience by syncing with a data feed.
- If you select New Variation, the template screen appears. Click the one you want, and then create your variation in JSON format.
- If you select Copy from Another Experience, your experience list appears.
Select the experience you want, and then either Copy Variation (takes you to the allocation step) or Copy and Edit (edit the JSON). - If you click sync it with a data feed, the template list appears. Select a template, and then select the feed to sync with.
- If you select New Variation, the template screen appears. Click the one you want, and then create your variation in JSON format.
- Click Save Variation.
- Repeat for as many variations as needed.
Step 3: Configure and save the experience
- Allocation:
- Set the allocation, primary metric, and advanced experience settings.
- Configure how much of your traffic to allocate to each variation and the control group.
- Click Next.
- Targeting:
- Configure the targeting settings of the experience to determine when, where, and for whom the experience is displayed, and then click Next.
- Save, preview, and publish:
- Save your experience as a draft if you want to preview and edit it before going live. When you're ready, set it to active and then save.
- Click the plus icon to create an additional targeted experience.
- Previewing:
- After you save the campaign, you can preview variations while editing them.
- To preview the campaign, go to your campaign list, hover over the campaign, and click the preview icon to see what the variation will look like to your visitor.
- When you're done, click Publish.
Calling a server-side custom campaign
In your code, you will use DYAP.choose() to request a variation of a campaign.
Path
https://dy-api.com/v2/serve/user/choose
HTTP Method |
|
Headers |
|
Body Parameters |
|
Node.JS Example
var request = require("request");
var options = {
method: 'POST',
url: 'https://dy-api.com/v2/serve/user/choose',
headers: {'content-type': 'application/json', 'dy-api-key': 'your-api-key'},
body: `{
"selector": {
"names": [
"test1"
]
},
"user": {
"id": "customUserId123"
},
"session": {
"custom": "myCustomSession345"
},
"context": {
"page": {
"type": "HOMEPAGE",
"location": "https://example.org",
"locale": "en_US",
"data":[]
},
"device": {
"userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
"ip": "54.100.200.255"
}
},
"options": {
"isImplicitPageview": false,
" returnAnalyticsMetadata": false
}}`
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
For more details, see the API reference.
Reporting Engagement
To report clicks on your campaigns to Dynamic Yield, use the Reporting Engagement API call.
For more details, see the API reference.
Validating your implementation
Check out the API Logs to see a history of recent API calls, their status, and much more.