Session ID

STYLE PTTRNS will allow you to get a session ID that STYLE PTTRNS generates. This will allow you to retrieve the favorites, recommendations etc. This is the unique ID on a user level. This is also the only input that STYLE PTTRNS will accept on a user.

Getting a session ID

It’s possible to get the user's session ID by listening to a window “message” event. This event will trigger and send a user session ID as soon as it is available, which is after the user takes a valid picture. The event contains two data values: "type" which indicates the type of event being sent and "sessionId" which contains the users' session ID. Below is the JavaScript code example.

var pttrnsSessionId = undefined;

window.addEventListener(
  'message',
  (event) => {
    if (event.data.type === 'onSessionIdUpdated') {
      console.log('The session id is', event.data.sessionId);

      // Save the session id in some way.
      pttrnsSessionId = event.data.sessionId;
    } 
  },
  false
);

Setting a session ID

It’s also possible to set a session ID. This only works with session IDs that already exist in our system and have been retrieved using the onSessionIdUpdated event. An example case for this could be to persist the same session ID for a user in your back-end that has multiple devices.

There are two ways of setting this value. This can be done by setting the session ID in the iframe URL as a query parameter, but it is more flexible to do so via calling postMessage on the contentWindow of the iframe, with an object containing a type of “updateSessionId” and the sessionId.

The following example gets the iframe of the previous example code, adds an onload listener and posts the message with a variable called pttrnsSessionId. The key points here are using the right iframe, waiting for it to load, and sending the object in the right format through postMessage.

const iframe = document.getElementsByClassName("recommender-iframe")[0];

iframe.onload = function () {
  iframe.contentWindow.postMessage(
    {
      type: "updateSessionId",
      sessionId: pttrnsSessionId,
    },
    "*"
  );
};

Deleting a session ID

We take user privacy very seriously. When we are provided with a session ID and a request to delete all related information we will always comply with this request. If you receive such a request from a user, please forward this request to your Customer Success Manager.