In Salesforce Marketing Cloud Personalization (formerly Interaction Studio), you can define page types within the Web SDK configuration (evergage.init(...)). A page type helps the system determine how to classify a given page and what data to capture. Developers often add custom attributes within these page type definitions to enrich the captured context.
Below are the two primary methods (from the listed options) where a developer can pass in or define attributes:
1. isMatch (Option A)
What It Is
isMatch is a function used to determine if a particular page type definition applies to the current page (based on URL, DOM elements, or other logic). It returns a boolean (true or false) to indicate whether the page matches this definition.
Passing Attributes
Inside the isMatch function, developers can add or modify attributes to enrich the context object. For example:
isMatch: function(context) {
// Check if page matches (e.g., URL pattern)
if (window.location.pathname.includes("/product/")) {
// Add custom attributes
context.addAttributes({
productCategory: "Shoes",
productType: "Sneakers"
});
return true;
}
return false;
}
This ensures that whenever this page type’s isMatch condition is true, certain attributes are set on the context.
Salesforce Reference
Salesforce Help: Web SDK Configuration GuideExplains how to set up page types, including using isMatch to define when a page type applies and how to add custom attributes.
2. onActionEvent (Option B)
What It Is
onActionEvent is a function within a page type definition that fires whenever an action event (e.g., click event, impression event) is triggered. You can use this to capture more specific or dynamic data each time an action is recorded.
Passing Attributes
Within onActionEvent, you can also manipulate the event or context to set additional attributes. For example:
onActionEvent: function(context, event) {
// For instance, if the user clicks a particular element:
if (event.action.name === "click") {
// Add or override attributes for this event
event.attributes = {
event.attributes,
clickedElementID: event.target.id
};
}
}
This approach is particularly useful for capturing data specific to user interactions (clicks, hovers, form submissions, etc.).
Salesforce Reference
Salesforce Help: Handling Action Events in the Web SDKDescribes how onActionEvent can be used to modify event data, including adding custom attributes.