Skip to main content

Setting and using a custom attribute

Let's create a customer session custom attribute referring to the customer's shipping city and use it in a rule to discount the session total.

Creating the customer session attribute

Let's create the custom attribute:

  1. Click Account in the left-most menu.
  2. Click Dev tools > Attributes.
  3. Click Create attribute at the top-right of the page.
  4. In Associated entity, choose the entity that will own the attribute. In our case, Customer session.
  5. In Attribute type, choose the type of value assigned to the attribute: String.
  6. In API name (internal), type the name of the attribute as you will use it in the integration layer. Let's use ShippingCity.
  7. In Title (visible), type the name of the attribute. It will appear in the palette. For example, Shipping city.
  8. In Description, type a description of what the attribute represents, such as Customer session shipping city
  9. In Suggestions, type down some potential values, such as Berlin, Paris, London, Madrid, Helsinki, Dublin and Lisbon.
  10. In Available in Applications, you can select the Applications where you want to use the attribute. We choose none, so the attribute will be available everywhere.
  11. Click Create attribute.

Setting the value of the attribute

The attribute is ready to be used by the integration layer. Since we have created a customer session attribute, its value is set programmatically using the customer session endpoint.

For example, we can set ShippingCity to Berlin with the following payload:


{
"customerSession": {
"profileId": "DE29HDG94NV",
"state": "open",
"cartItems": [
{
"name": "Camera",
"sku": 483092756,
"quantity": 2,
"price": 159.99
}
],
"attributes": {
"ShippingCity": "Berlin"
}
},
"responseContent": [
"customerSession",
"customerProfile"
]
}

Issuing a discount on the session total

Let's build the rule for customers who choose Berlin as their shipping city to receive a discount:

  1. Click Rule Builder in the left-side menu of our campaign.
  2. Click Add Rule.
  3. Type a name for your rule. For example, Discount on session total when shipping to Berlin.
  4. In Conditions, click Add condition.
  5. Click Validate attribute value.
  6. Select Shipping city (current session) in the palette.
  7. In the drop-down menu, choose is equal to.
  8. Select a city in the drop-down menu with all our suggestions or type the name of another city. In our example, we choose Berlin, which appears on the list.
  9. Click Done.
  10. In Effects, click Add effect.
  11. Click Discount session total.
  12. In Discount name, type a suitable name, such as Berlin 10% off.
  13. Set Discount value to [Session.Total]*10%.
  14. Click Done.
  15. Click Save at the top right of the page.

Now, when a customer with Berlin as their current shipping city adds items to their cart, they will see a 10% discount applied to it.