Working with session data

When you initiate a session with the startSession method, session data is loaded into memory. Throughout the session, you can read and write to the session data (which is a superset of the static profile data).

The session contains the following data:

  • Static profile data
  • Segment assignments
  • Real-time data
  • Offer recommendations

All session data is available until you call the endSession method, or the sessionTimeout time elapses. Once the session ends, all data not explicitly saved to contact or response history or some other database table is lost.

The data is stored as a set of name-value pairs. If the data is read from a database table, the name is the column of the table.

You can create these name-value pairs as you work with the Unica Interact API. You do not need to declare all name-value pairs in a global area. If you set new event parameters as name-value pairs, the runtime environment adds the name-value pairs to the session data. For example if you use event parameters with the postEvent method, the runtime environment adds the event parameters to the session data, even if the event parameters were not available in the profile data. This data exists in the session data only.

You can overwrite session data at any time. For example, if part of the customer profile includes creditScore, you can pass in an event parameter using the custom type NameValuePair. In the NameValuePair class, you can use the setName and setValueAsNumeric methods to change the value. The name needs to match. Within the session data, the name is not case-sensitive. Therefore, the name creditscore or CrEdItScOrE would both overwrite creditScore.

Only the last data written to the session data is kept. For example, startSession loads the profile data for the value of lastOffer. A postEvent method overwrites lastOffer. Then a second postEvent method overwrites lastOffer. The runtime environment keeps only the data written by the second postEvent method in the session data.

When the session ends, the data is lost, unless you made special considerations such as using a Snapshot process in your interactive flowchart to write the data to a database table. If you are planning on using Snapshot processes, remember that the names need to match the limitations of your database. For example, if your are allowed only 256 characters for the name of a column, then the name for the name-value pair should not exceed 256 characters.