5.2 Send user events to Moloco Commerce Media
To send marketplace user events to Moloco Commerce Media, you must send a POST API request to the user event API with your platform ID as in the following example. Moloco will provide your {platform_name} and {platform_id}.
https://{platform_name}-evt.rmp-api.moloco.com/rmp/event/v1/platforms/{platform_id}/userevents
The request header must include your API key as in the following example.
"Content-Type": "application/json"
"X-API-Key": "{api_key}"
Caution
Your request body must be in JSON object format. You can include the following properties in the request body. For more information, see the User Event API reference.
To enable API integration testing, Moloco provides two platform_ididentifiers one for testing and one for actual ingestion. Using the test platform_id, you may send test requests and receive test responses.
The User Event API client GitHub repository contains detailed request format examples based on a code library implemented with JavaScript/TypeScript.
Sending ADD_TO_CART
event
ADD_TO_CART
event// This example is for reporting your events server-to-server (S2S).
import { client } from '../common/event-api-client';
import usParser from 'ua-parser-js';
const { session, headers } = req;
const ua = usParser(headers['user-agent']);
client.insertEvent({
id: randomString(),
eventType: 'ADD_TO_CART',
timestamp: Date.now(),
channelType: 'SITE',
userId: session.user.id,
device: {
os: ua.os.name,
osVersion: ua.os.version,
model: ua.device.model,
ip: req.socket.remoteAddress,
},
items: [
{
id: product.id,
price: product.salePrice
quantity: product.quantity,
},
],
pageId: `CATEGORY_HOME_PAGE:${categoryId}`,
referrerPageId: `PRODUCT_DETAIL_PAGE:${productId}`,
});
Sending PURCHASE
event
PURCHASE
eventclient.insertEvent({
id: randomString(),
eventType: 'PURCHASE',
timestamp: Date.now(),
channelType: 'SITE',
userId: session.user.id,
device: {
os: ua.os.name,
osVersion: ua.os.version,
model: ua.device.model,
ip: req.socket.remoteAddress,
},
items: products.map((product) => ({
id: product.id,
price: product.salePrice,
quantity: product.quantity,
})),
revenue: {
currency: 'USD',
amount: totalAmount,
},
pageId: 'ORDER_SUMMARY_PAGE'
referrerPageId: 'CART_PAGE',
});
Sending ITEM_PAGE_VIEW
event
ITEM_PAGE_VIEW
eventclient.insertEvent({
id: randomString(),
eventType: 'ITEM_PAGE_VIEW',
timestamp: Date.now(),
channelType: 'SITE',
userId: session.user.id,
device: {
os: ua.os.name,
osVersion: ua.os.version,
model: ua.device.model,
ip: req.socket.remoteAddress,
},
items: [
{
id: product.id,
price: product.salePrice
quantity: 1,
},
],
pageId: `PRODUCT_DETAIL_PAGE:${productId}`,
referrerPageId: `CATEGORY_HOME_PAGE:${categoryId}`,
});
Updated about 1 month ago