How we track visitors as they move around your site or app
In the Quick Guide, you saw how to get a simple decision from a Conductrics Agent:
GET http://api.conductrics.com/acme/agent-1/decision
And how to send a reward to the Agent:
POST http://api.conductrics.com/acme/agent-1/goal
You might be wondering:
How does the service know that the goal is conceptually connected to the decision?
In other words, how does the service track visitors?
Does it set a cookie? If so, how can that work when calling Conductrics from a server?
This page should answer those questions for you.
All decisions and goals happen in the context of a 'Session' which is remembered by your agent.
We need a Session ID to keep the sessions straight. You can provide the Session ID, or we can make it up for you.
Without the concept of Session IDs, we wouldn't have a good way of matching goals back to the decisions that led to them. Our service wouldn't be able to learn.
If you are using our service 'client-side', meaning that you are making calls to our service via AJAX / jQuery / JavaScript, then to make things simple, our service is happy to set a cookie with the Session ID.
This cookie support also works great with our Simple Redirects feature, so you don't need to use any scripting at all.
For details, see Automatic Cookies, below.
If you're calling our API from the 'server-side', or any other scenario where cookies don't apply, you need to pass us a session ID.
You pass the ID as a URL parameter called session, or as an HTTP header called x-mpath-session. The value can be just about any string you make up, as long as it's unique to a given 'visit' or 'session'.
Often, you will have a 'session' or 'visit' type of ID on hand already, via whatever software or framework you are calling our service from. You can just use that (or a hash of it) as the ID you pass to us.
If you don't pass an ID, we'll make one up and return it in our response. It's up to you to pass us back that same ID for the next request from the same conceptual session.
It's best if the ID you provide contains only letters, numbers, underscores and dashes (if not, we will still accept it, but we'll strip out any spaces or other characters and use that--the cleaned ID will come back in our response).