Interaction Event Options in the SalesforceInteractions Namespace

The following code sample details the event options available in the SalesforceInteractions namespace in the Personalization module of the Salesforce Interactions SDK.

1interface ActionEvent<InteractionType extends Interaction> {
2    interaction: InteractionType;
3    debug?: boolean;
4    flags?: boolean;
5    user?: User;
6    account?: Account;
7    source?: Source;
8    consents?: Consent[];
9    explain?: boolean; // If true, then return additional information in the response about why campaigns did or did not render. Requires authentication.
10    pageView?: boolean; // If true, indicates that the event was triggered from a page load.
11    time?: number; // The date and time of the event (in milliseconds) elapsed since the UNIX epoch. This field is optional and will be auto-populated with the current time if null.
12    performance?: PerformanceMetrics;
13    campaignStats?: CampaignStat[],
14}

The interaction Object 

The interaction object has the following structure.

1{
2    interaction: Interaction,
3    ...
4}

Interaction 

You can use the Interaction field to capture user engagement data. The Interaction field has the following structure.

1interface Interaction {
2  name: string;
3}

CatalogObjectInteraction 

This type of Interaction is used to capture engagement data about catalog objects.

1interface CatalogObjectInteraction extends Interaction {
2    name: CatalogObjectInteractionName;
3    catalogObject: CatalogObject;
4}
5
6interface CatalogObject {
7    type: string;
8    id: string;
9    attributes?: { [key: string]: any };
10    relatedCatalogObjects?: { [catalogObjectType: string]: string[] };
11}
12
13enum CatalogObjectInteractionName {
14    ViewCatalogObject = 'View Catalog Object',
15    ViewCatalogObjectDetail = 'View Catalog Object Detail',
16    QuickViewCatalogObject = 'Quick View Catalog Object',
17    ShareCatalogObject = 'Share Catalog Object',
18    ReviewCatalogObject = 'Review Catalog Object', // This Interaction is not supported in Marketing Cloud Personalization
19    CommentCatalogObject = 'Comment Catalog Object',
20    FavoriteCatalogObject = 'Favorite Catalog Object'
21}

The location Object 

You can use the location object to send location data on a catalogObject via the Event API or using the Sitemap. The following is an example of how to structure a catalogObject to include location data.

1"catalogObject": {
2    "id": "test_product_one",
3    "type": "Product",
4    "attributes": {
5        "location": {
6            "longlat": [-71.1502415, 42.3571222],
7            "city": "Boston",
8            "stateProvinceCode": "MA",
9            "postalCode": "02134",
10            "countryNumericCode": "840"
11        }
12    }
13}

The following examples depict sending data for locations outside the US.

1"catalogObject": {
2    "id": "test_product_two",
3    "type": "Product",
4    "attributes": {
5        "location": {
6            "longlat": [144.963058, -37.813629],
7            "city": "Melbourne",
8            "stateProvinceCode": "VIC",
9            "postalCode": "3005",
10            "countryNumericCode": "036"
11        }
12    }
13}
1"catalogObject": {
2    "id": "test_product_three",
3    "type": "Product",
4    "attributes": {
5        "location": {
6            "longlat": [139.691711, 35.689487],
7            "city": "Tokyo",
8            "stateProvinceCode": "13",
9            "postalCode": "100-0004",
10            "countryNumericCode": "392"
11        }
12    }
13}

CartInteraction 

This type of Interaction is used to capture engagement data about the contents of a user’s cart.

1enum CartInteractionName {
2    AddToCart = 'Add To Cart',
3    RemoveFromCart = 'Remove From Cart',
4    ReplaceCart = 'Replace Cart'
5}
6
7interface CartInteraction extends Interaction {
8    name: CartInteractionName;
9}
10
11interface AddToCartInteraction extends CartInteraction {
12    name: CartInteractionName.AddToCart;
13    lineItem: LineItem;
14}
15
16interface RemoveFromCartInteraction extends CartInteraction {
17    name: CartInteractionName.RemoveFromCart;
18    lineItem: LineItem;
19}
20
21interface ReplaceCartInteraction extends CartInteraction {
22    name: CartInteractionName.ReplaceCart;
23    lineItems: LineItem[];
24}

At this time, the Personalization Event Stream report doesn’t display ReplaceCart interactions. Instead, if you use SalesforceInteractions.CartInteractionName.ReplaceCart, the associated ReplaceCart interactions appear in the Event Stream report as “View Cart” interactions.

Note

OrderInteraction 

This type of Interaction is used to capture engagement data about the items in a user’s order. Only the PurchaseOrderInteraction affects and updates a user’s current order.

1interface Order {
2    id: string;
3    lineItems?: LineItem[];
4    totalValue?: number;
5    currency?: string;
6    attributes?: { [key: string]: any };
7}
8
9enum OrderInteractionName {
10    Purchase = 'Purchase',
11    Preorder = 'Preorder',
12    Cancel = 'Cancel',
13    Ship = 'Ship',
14    Deliver = 'Deliver',
15    Return = 'Return',
16    Exchange = 'Exchange'
17}
18
19interface OrderInteraction extends Interaction {
20    name: OrderInteractionName;
21    order: Order;
22}
23
24interface PurchaseOrderInteraction extends OrderInteraction {
25    name: OrderInteractionName.Purchase;
26    order: Order;
27}
28
29interface PreorderOrderInteraction extends OrderInteraction {
30    name: OrderInteractionName.Preorder;
31    order: Order
32}
33
34interface CancelOrderInteraction extends OrderInteraction {
35    name: OrderInteractionName.Cancel;
36    order: Order
37}
38
39interface ShipOrderInteraction extends OrderInteraction {
40    name: OrderInteractionName.Ship;
41    order: Order
42}
43
44interface DeliverOrderInteraction extends OrderInteraction {
45    name: OrderInteractionName.Deliver;
46    order: Order
47}
48
49interface ReturnOrderInteraction extends OrderInteraction {
50    name: OrderInteractionName.Return;
51    order: Order
52}
53
54interface ExchangeOrderInteraction extends OrderInteraction {
55    name: OrderInteractionName.Exchange;
56    order: Order
57}

Line Item 

A LineItem represents a single item in a cart or transaction. A LineItem object has the following structure.

1interface LineItem {
2  catalogObjectType: string;
3  catalogObjectId: string;
4  quantity: number;
5  price: number;
6  currency?: string;
7  attributes?: { [key: string]: any }; // Include sku under attributes
8}

The following table describes the properties that a LineItem object accepts.

PropertyValue TypeDescription
catalogObjectTypeStringThe type representing the catalog object.
catalogObjectIdStringA unique ID representing the catalog object.
quantityNumberThe number of catalog objects in the line item.
priceNumberThe price of the catalog object in the line item. Important: price is mandatory only when using LineItem in a purchase or cart interaction, and optional for other interactions.
currencyStringOptional. Currency code of purchase. If currency is unspecified or null, it defaults to the dataset’s configured currency.
attributes{[key: string]: string | number | boolean }Optional. Key-value pairs that are stored as metadata on the LineItem. You can include sku within attributes.

The following is an example of a line item used within an AddToCart interaction.

1// Example: Without SKU
2{
3	interaction: {
4		name: "Add To Cart",
5		lineItem: {
6			catalogObjectType: "Product",
7			catalogObjectId: "product-1",
8			quantity: 1,
9			price: 9.99,
10			currency: "USD",
11			attributes: {
12				giftWrapping: 1
13			}
14		}
15	}
16}
17
18// Example: With SKU
19{
20	interaction: {
21		name: "Add To Cart",
22		lineItem: {
23			catalogObjectType: "Product",
24			quantity: 1,
25			price: 9.99,
26			currency: "USD",
27			attributes: {
28				sku: {
29					id: "sku12345"
30				}
31			}
32		}
33	}
34}

At this time, the Personalization Event Stream doesn’t display price for AddToCart events.

Note

The consent Object 

The consent field accepts an array of consent objects for the user. The following table describes the various properties available in the consent object.

PropertyValue TypeDescription
purposeStringThe purpose for the consent. For example, Personalization.
providerStringThe consent provider
statusStringThe consent status. For example, OptIn or OptOut

The debug Object 

The debug object contains fields that help investigate issues that could arise when developing campaigns.

The following table describes the properties available in the debug object.

PropertyValue TypeDescription
testMessagesStringA comma-separated list of campaign experience IDs to be forced to return in the event, ignoring rules that otherwise prevent the campaign from returning. Alternatively, you can use the string value true to return all campaigns in testing mode but all rules are respected.

The flags Object 

The flags object contains properties that alter default event processing. By default, all flags are false if not present on the event.

The following table describes the various properties available in the flags object.

PropertyValue TypeDescription
noCampaignsBooleanIf true, don’t return campaigns in the response.
nonInteractiveBooleanIf true, a visit isn’t created (or updated) for the given user in the event. Additionally, no visit referrer nor originating referrer is created for the user.

Source 

The Source object contains properties that help describe where an event is coming from. This object has the following structure.

1interface Source {
2    channel?: string,
3    application?: string,
4    pageType?: string,
5    url?: string,
6    urlReferrer?: string,
7    locale?: string,
8    contentZones?: string,
9    configVersion?: number,
10    userAgent?: string,
11    clientIp?: string,
12    operatingSystem?: string // only applicable for mobile events
13    operatingSystemVersion?: string // only applicable for mobile events
14    device?: string // only applicable for mobile events
15    surveyId?: string // set through the Survey Gear
16    surveyStartTime?: string // set through the Survey Gear
17}

The following table describes the various properties available in the Source object.

PropertyValue TypeDescription
channelStringThe originating source of the event (For example, Web, MobileApp, CallCenter).
applicationStringThe originating application level source of the event (For example, ReactApp, 3rdParty, ReactNative)
pageTypeStringThe type of page from which you’re sending the event (For example, PDP, Blog, Pricing).
urlStringThe URL of the page from which you’re sending the event.
urlReferrerStringThe previous URL visited by the user. urlReferrer is populated from document.referrer by default on the web. It can be overwritten in the sitemap to any other value if necessary.
localeStringThe locale of the current page, as defined by ISO 639 alpha-2 language codes and ISO 3166 alpha-2 country codes (For example, en_US, de_DE).
contentZonesstring[]An array of content zones on the current page.
configVersionNumberVersion number of the configuration for the SDK.
userAgentStringThe user agent for the event. userAgent is populated automatically but can be overwritten if necessary
clientIpStringThe IP Address sending the event. clientIp is populated automatically but can be overwritten if necessary
operatingSystemStringOnly applicable for mobile events.
operatingSystemVersionStringOnly applicable for mobile events.
deviceStringOnly applicable for mobile events.
surveyIdStringThe ID of the survey being submitted. Set automatically for events sent through the Survey Gear
surveyStartTimeStringThe start time of the survey being submitted. Set automatically for events sent through the Survey Gear

The User Object 

The User object describes the user associated with an event.

1interface User {
2  anonymousId?: string;
3  identities?: {
4    [key: string]: string,
5  };
6  attributes?: {
7    [key: string]: string | number | boolean,
8  };
9  profileObjects?: {
10    [profileObjectType: string]: ProfileObject[],
11  };
12}

The following table describes the various properties available in the user object.

PropertyValue TypeDescription
anonymousIdStringThe ID of an anonymous user.
identities[key: string]: stringKey-value pairs that are stored as identity information of a user.
encryptedIdStringThe encrypted ID returned from an event that contains the ID field. Encrypted IDs are returned in the response to events that provide identities.
attributes{ [key: string]: string | number | boolean }Key-value pairs that are stored as metadata on the user. These attributes must be defined in the platform.
profileObjects{ [profileObjectType: string]: ProfileObject[] }Key-value pairs of profile objects that are stored as metadata on the user. Profile objects, their attributes, and related catalog objects must be defined in the platform.

Profile Object 

You can use the profileObjects field to send new or update existing profile objects via the Event API or using the Web SDK. You can send multiple profile objects of one type or multiple types in a single event.

1interface ProfileObject {
2  id: string;
3  relatedCatalogObjects?: { [catalogObjectType: string]: string[] };
4  attributes?: { [key: string]: string | number | boolean };
5}

To enable Strict Profile Object Security, log on to the Personalization UI and navigate to Settings > Catalog and Profile Objects > User Profile Object Settings. Enabling this setting restricts profile object updates to authenticated event sources such as ETL and Event API calls that use channel: Server and the /authevent endpoint. After it’s enabled, updates to profile objects from unauthenticated channels such as Web are ignored.

Note

  • If an event causes a user to exceed 100 profile objects of a specific type, the 100 most recent objects are retained based on their creation date.
  • You can’t selectively update the fields of a profile object. You can only replace each instance of a profile object entirely. If you’re updating an existing profile object, fields in the incoming event entirely replace the user’s existing profile object fields.
  • You can’t entirely replace a set of profile objects of a given type with another set or an empty set. For example, an event with profileObjects: { Lease: [] } doesn’t clear out all Leases on that given user.
  • You can only create new or replace existing profile objects with Event API calls and not remove them.

Important

The following table describes the properties that a ProfileObject accepts.

PropertyValue TypeDescription
idStringThe ID of a Profile Object.
relatedCatalogObjects{ [catalogObjectType: string]: string[] }Related catalog objects key-value pairs. These related catalog objects must be defined in the platform.
attributes{ [key: string]: string | number | boolean }Attribute key-value pairs that are stored as metadata on the profile object record. These attributes must be defined in the platform.

The following example depicts sending a single “Lease” profile object record with attributes and related catalog objects.

1"profileObjects": {
2    "Lease": [
3        {
4            "id": "55X1V44",
5            "relatedCatalogObjects": {
6                "Color": ["red", "blue"],
7                "Make": ["car company"]
8            },
9            "attributes": {
10                "duration": 365,
11                "startDate": 1641502977863
12            }
13        }
14    ]
15}

The Account Object 

The Account object describes the account associated with an event.

1interface Account {
2  id?: string;
3  attributes?: {
4    [key: string]: string | number | boolean,
5  };
6}

The following table describes the various properties available in the account object.

PropertyValue TypeDescription
idStringThe ID of an account.
attributes{ [key: string]: string | number | boolean }Key-value pairs that are stored as metadata on the account. These attributes must be defined in the platform.

The PerformanceMetrics Object 

The PerformanceMetrics object has properties that measure loading, parsing, and network performance.

1interface Performance {
2  sdkLoadTimeMs?: number;
3  sdkParseTimeMs?: number;
4  pageLoadTimeMs?: number;
5  networkTimeMs?: number;
6}

The following table describes the various properties available in the PerformanceMetrics object.

PropertyValue TypeDescription
sdkLoadTimeMsNumber(Web SDK) Time, in milliseconds, for the network to load the web SDK.
sdkParseTimeMsNumber(Web SDK) Time, in milliseconds, for the beacon to be parsed during page load.
pageLoadTimeMsNumber(Web SDK) Time, in milliseconds, for the DOM to load.
networkTimeMsNumber(Web SDK) Time, in milliseconds, for the previous request to return.

The campaignStats Object 

You can use the campaignStats object to track campaign statistics for an associated event.

For more information on sending campaign statistics on the web, refer to the Campaign Stats Tracking documentation.

The campaignStats object has the following structure.

1{
2    ...
3    {
4        campaignStats: CampaignStat[]
5    }
6    ...
7}

The CampaignStat Object 

The CampaignStat object has the following structure.

1{
2    experienceId: string,
3    stat: "Impression" | "Click" | "Dismissal",
4    control: boolean,
5    catalog: {
6        <ItemType>: string[]
7    }
8}

The following table describes the properties a CampaignStat object accepts.

PropertyValue TypeDescription
experienceIdStringThe experience ID of the campaign on which the given statistic is being tracked
stat"Impression" | "Click" | "Dismissal"The type of statistic being tracked.
controlBooleanIf true, the statistic is tracked for the control group of the given experience.
catalog{ <ItemType>: string[] }A mapping of catalog item types to a list of corresponding item IDs on which to attribute the given statistic.

The following is an example of a mapping of catalog item types.

1...
2catalog: {
3    Product: ["product1", "product2"]
4}
5...