---
schema_version: "1"
id: 12667b31a3cb494a874e16dd50a8607a394c697a751a455b89f5574bd90ef782
title: Using Session Custom Attributes in B2C Commerce
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/cc/264-0-0/b2c_using_session_custom_attributes.md
canonical_url: https://help.salesforce.com/s/articleView?id=cc.b2c_using_session_custom_attributes.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: e89d7c6cf4ccb3cc400c50763bfa6c071c626a832b2a21bf55b36b91616f7c6a
description: Using session custom attributes, you can customize unique session information to identify customers for a customer group. To do this, configure customized session custom attributes in Business Manager and in your application.
products:
  - Commerce
  - B2C Commerce
release: "264"
---
# Using Session Custom Attributes in B2C Commerce

Using session custom attributes, you can customize unique session information to identify customers for a customer group. To do this, configure customized session custom attributes in Business Manager and in your application.

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-cc-b2c_merchandiser_administrator-264-0-0-production-enus/ea76f372-6cfa-42a6-8e7c-05c6df7abed8/images/icon_note.png)

Note For all API responses with session custom attributes, the default attribute name 'Session Custom Attribute' is used.

## Setting Session Custom Attributes

First, you must define a customer group to use session custom attributes. See [Creating a Dynamic Customer Group.](https://help.salesforce.com/s/articleView?id=cc.b2c_creating_a_dynamic_customer_group.htm&release=264.0.0&type=5 "A dynamic customer group is a group with changing membership. Membership is based on purchase history, profile, address, or active data. You can also base membership on membership in system and static customer groups. You can't base membership on dynamic customer groups.")

Then, you must set a custom session attribute using "session.custom.<attributename> =" in your application.

For example: `session.custom.firstname = "Suri"; _firstName = session.custom.firstname`

These attributes are defined implicitly when they’re set and are stored in the session.

## Parsing Session Custom Attributes

Salesforce B2C Commerce doesn't have metadata about session custom attributes and hence doesn't know the actual attribute type. It can only evaluate session custom attribute conditions in a meaningful way if the condition is applicable for the actual type of the session custom attribute. It tries to determine the intended session type when creating a condition rather than determining it during rule evaluation.

| If the selected operator used is... | B2C Commerce assumes |
| --- | --- |
| 'exists', 'don't exist' | String |
| 'is greater than', 'is less than', 'is greater than or equals', 'is less than or equals', 'is in range' | Number |
| 'is true', 'is false' | Boolean |
| 'starts with', 'ends with', 'contains', 'doesn't contain' | String |
| 'is equal', 'isn’t equal' | If the value string representation is "true" or "false", we assume Boolean |
|   | If the value string starts with a number, we assume Number |
|   | Else, we assume String |

If a condition isn't applicable for the actual type of the session custom attribute, the condition doesn't match. For example, if during rule evaluation, the session custom attribute evaluates to a number from the customer's session, but the actual type is Boolean, the condition evaluates to false.

## Using "Is Equal" with Session Custom Attributes

Conditions on string values are converted into conditions on numeric or Boolean values, with these specific conditions, all of which must apply:

- A rule condition evaluates on a session custom attribute
- The operator of the rule condition is _is equal_
- The condition values and the session custom attributes are numeric or Boolean-like data

If it isn't a session custom attribute, or the operator isn't _is equal,_ or at least one condition value isn't numeric or boolean, Business Manager treats it as a string. Previously, the assignment to a session-based customer group didn’t work when the membership rule had the previous conditions.

For example, with customers with the session custom attribute 'solvencyScore' = '4', where the session attribute is a _number,_ that is, Double(4.0), B2C Commerce stored and evaluated the conditions like conditions on strings. B2C Commerce converted the number into the string "4.0", and compared it with the condition value "4", which didn’t match.

In Business Manager, when you define the values for session custom attributes:

- For numeric values, they must be like "4", "4.0", "4.567", but not "foo", 123,456.67", or "123,45". For example, "myAttribute is equal `[4.5]`" is converted to "myAttribute = 4.5".
- \# For boolean values, they must be like "true", "false", "True", but not "foo", "123,456.67", or "123,45". For example, a condition "myAttribute is equal `[true]`" is converted to "myAttribute is true".

Rule Evaluation

Numeric conditions on session custom attributes now match if the value of the session custom attribute is a string. Previously, a numeric condition didn’t match in this situation.

Numeric condition on a string attribute

For example, this rule with a numeric condition applies on a session custom attribute with a string value: "session.custom.myAttribute = 4.0"

| Value of myAttribute | Rule matched previously | Rule matched now |
| --- | --- | --- |
| "foobar" | No | No |
| "4" | No | Yes |
| "4.0" | No | Yes |
| "4.5" | No | No |

String condition on numeric attribute

We didn’t change the way B2C Commerce processes a rule with a string condition on a session custom attribute with a numeric value. For example "session.custom.myAttribute is equal `[4,4.1 beta]`" applies as follows:

| Value of myAttribute | Rule matched previously |
| --- | --- |
| 4 | Yes |
| Decimal("4") | Yes |
| BigInteger("4") | Yes |
| 4.0 | No |
| 4.5 | No |
| Number("4") | No |
| Number("4.5") | No |
| Decimal("4.5") | No |

![Tip](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-cc-b2c_merchandiser_administrator-264-0-0-production-enus/ea76f372-6cfa-42a6-8e7c-05c6df7abed8/images/icon_tip.png)

Tip If you like the way this rule works, use "session.custom.myAttribute is equal `[4,4.0]`".

## Related Links

[Dynamic Customer Group Rules](https://help.salesforce.com/s/articleView?id=cc.b2c_dynamic_customer_group_rules.htm&release=264.0.0&type=5 "A dynamic customer group has exactly one rule with one or more conditions. A condition is an individual line in the editor, for example, Company equals ‘Salesforce’.")

[Creating a Dynamic Customer Group](https://help.salesforce.com/s/articleView?id=cc.b2c_creating_a_dynamic_customer_group.htm&release=264.0.0&type=5 "A dynamic customer group is a group with changing membership. Membership is based on purchase history, profile, address, or active data. You can also base membership on membership in system and static customer groups. You can't base membership on dynamic customer groups.")

[Customer Groups Object Import Export](https://help.salesforce.com/s/articleView?id=cc.b2c_customer_group_object_import_export.htm&release=264.0.0&type=5 "You can use the elements in the customergroup.xsd and considerations when creating values for them.")