JavaScript Integration
Full programmatic control over event tracking. Use rcdp.executeEventByData() to fire any event with complete flexibility over payload construction.
Copy, Paste, Go
Add this snippet before your closing </body> tag and replace <TENANT_HASH> and <SITE_HASH> with your onboarding values.
Add before </body>
<!-- Add before </body> in your HTML -->
<script type="text/javascript"
src="https://rcdp-us.algonomy.com/js/<TENANT_HASH>/<SITE_HASH>.js"
async>
</script>
Verify in browser console
// Open browser console (F12) and verify:
console.log(typeof rcdp); // → "object"
That's it. You're ready to fire events.
Core Principle
You provide only the business data (what happened). The SDK automatically constructs all metadata, formats the payload, and transmits it to Real-time CDP.
The only method you need
rcdp.executeEventByData(eventData, eventType);
// eventData → Your business object (product, cart, order…)
// eventType → Event name string ("eventProduct", "eventAddToCart"…)
What the SDK Handles Automatically
You don't build metadata, manage sessions, or handle API calls. The SDK does all of this:
Auto-Constructs Metadata
- → srcId & srcType
- → requestTime (epoch)
- → Session context
- → Page context (URL, title, referrer)
- → Device & browser fingerprint
- → Identity correlation
Consent-Aware Collection
- → Cookie behavior adapts to consent state
- → If consent is enabled, it must be handled
- → Events will not fire without consent
Fires Implicit Events
- → Session creation & renewal
- → Device synchronization
- → Identity updates
- → Page lifecycle
Manages Transmission
- → JSON payload formatting
- → API endpoint routing
Complete Event Reference
Copy-paste ready examples for every supported event. Each event only requires the eventData object — the SDK handles everything else.
Supported events:
Navigation
Home Page - eventHomePage
No eventData needed — the SDK captures page context automatically.
rcdp.executeEventByData({}, "eventHomePage");
Search - eventSearch
rcdp.executeEventByData({
searchFacet: "shoes",
searchString: "blue shoes",
searchResults: "42",
searchResponseTime: "120"
}, "eventSearch");
Category Page - eventCategory
rcdp.executeEventByData({
parentCategoryId: "parent001",
categoryId: "cat001"
}, "eventCategory");
Product
Product View - eventProduct
rcdp.executeEventByData({
categoryId: "cat001",
productId: "prod001",
price: "160.00",
brandId: "brd001"
}, "eventProduct");
Cart
Add to Cart - eventAddToCart
rcdp.executeEventByData({
sku: "sku001",
categoryId: "cat001",
productId: "prod001",
price: "160.00",
quantity: "1",
totalQuantity: "2"
}, "eventAddToCart");
Edit Cart Item - eventCartItemEdit
rcdp.executeEventByData({
cartId: "cart123",
cartProducts: [{
productId: "814",
categoryId: "222",
productPosition: "Cart",
action: "Edit Cart",
quantity: 1,
productBasePrice: 210.00,
tax: 17.33,
sku: "sku123",
discount: 5.00,
couponCode: "DISCOUNT2024"
}]
}, "eventCartItemEdit");
Transaction
Checkout - eventCheckout
rcdp.executeEventByData({
transactionId: "727",
tenderType: "cash",
checkoutType: 0,
totalPrice: 227.33,
shippingCost: 0.00,
discount: 0,
couponCode: null,
cartId: "cart123",
cartProducts: [
{
productId: "814",
productPosition: 1,
action: "Checkout",
quantity: 1,
productBasePrice: 210.00,
tax: 17.33,
sku: "sku",
discount: 0.00,
couponCode: null
}
],
billingInfo: {
firstName: "John",
lastName: "Smith",
line1: "4/40",
cityCode: "Chicago",
stateCode: "IL",
zip: "60001",
countryCode: "IN",
emailAddress: "john.smith@example.com",
phoneNumber: "1234567890"
},
shippingInfo: {
firstName: "John",
lastName: "Smith",
line1: "4/40",
cityCode: "Chicago",
stateCode: "IL",
zip: "60001",
countryCode: "IN",
emailAddress: "john.smith@example.com",
phoneNumber: "1234567890"
}
}, "eventCheckout");
Transaction Complete - eventTransactionComplete
rcdp.executeEventByData({
transactionId: "727",
orderId: "123",
tenderType: "cash",
checkoutType: 0,
totalPrice: 227.33,
shippingCost: 0.00,
discount: 0,
couponCode: null,
totalItemCount: 1,
cartProducts: [
{
productId: "814",
quantity: 1,
productBasePrice: 210.00,
tax: 17.33,
sku: "sku",
discount: 0.00,
couponCode: null
}
],
billingInfo: {
firstName: "John",
lastName: "Smith",
line1: "4/40",
cityCode: "Chicago",
stateCode: "IL",
zip: "60001",
countryCode: "IN",
emailAddress: "john.smith@example.com",
phoneNumber: "1234567890"
},
shippingInfo: {
firstName: "John",
lastName: "Smith",
line1: "4/40",
cityCode: "Chicago",
stateCode: "IL",
zip: "60001",
countryCode: "IN",
emailAddress: "john.smith@example.com",
phoneNumber: "1234567890"
}
}, "eventTransactionComplete");
Transaction Failure - eventTransactionFailure
rcdp.executeEventByData({
orderId: "123",
errorCode: "PAYMENT_DECLINED",
errorMessage: "Card was declined"
}, "eventTransactionFailure");
Identity
Customer Create - eventCustomerCreate
Always call rcdp.setCustomer() before identity events to enable cross-device stitching.
// Step 1: Set the customer identity
rcdp.setCustomer({
email: "user@mail.com",
mobile: "9000000000",
customerCode: "100"
});
// Step 2: Fire the event
rcdp.executeEventByData({
customerCode: "100",
customerEmailId: "user@mail.com",
mobileNo: "9000000000",
firstName: "John",
lastName: "Smith",
gender: "Male",
dob: "12-30-2000",
joiningDate: "01-15-2024"
}, "eventCustomerCreate");
Login - eventLogin
rcdp.setCustomer({
email: "user@mail.com",
customerCode: "100"
});
rcdp.executeEventByData({
customerCode: "100"
}, "eventLogin");
Update Profile - eventUpdateProfile
rcdp.executeEventByData({
customerCode: "100",
firstName: "Jane",
lastName: "Smith",
customerEmailId: "jane@mail.com",
gender: "Female",
dob: "05-15-1990"
}, "eventUpdateProfile");
Logout - eventLogout
rcdp.executeEventByData({}, "eventLogout");
Forgot Password - eventForgotPassword
rcdp.executeEventByData({
customerEmailId: "user@mail.com"
}, "eventForgotPassword");
Engagement
Share Wishlist - eventShareWishlist
rcdp.executeEventByData({
wishlistId: "wl001",
shareMethod: "email"
}, "eventShareWishlist");
Identity Management
Use rcdp.setCustomer() to link a session to a known customer. This enables cross-device identity stitching and personalization.
Setting customer identity
const customerObj = {
email: "user@mail.com", // Primary identifier
mobile: "9000000000", // Optional
customerCode: "CUST-100" // Your internal customer ID
};
rcdp.setCustomer(customerObj);
// Call this on login, registration, or any identity event
Call this on login, registration, or any identity event.
When to call setCustomer
Call rcdp.setCustomer() as soon as you know who the user is — typically on login, registration, or if you resolve their identity from a cookie or token. All subsequent events will be attributed to this customer.
Consent Handling
The SDK does not manage consent internally. If cookie consent is enabled on your website, you must explicitly handle it. If the user has not accepted consent, events should not be fired.
Example: Gate events behind CMP (OneTrust, Cookiebot, etc.)
// Listen for consent updates from your CMP
window.addEventListener('consentUpdated', function(e) {
if (e.detail.analytics) {
// User accepted — now safe to fire events
rcdp.executeEventByData(eventData, eventType);
}
});
// Or check consent state before firing
function trackIfConsented(eventData, eventType) {
if (hasUserConsented()) { // your consent check
rcdp.executeEventByData(eventData, eventType);
}
}
For the full consent architecture, see Consent Management.