Answers - Custom Frontend - Persisting Session with Session ID

We’ve implemented Yext Answers into a custom front-end. We’re querying the Yext Answers API and rendering the results on our side.

I’m reviewing the documentation now, and I’m not sure that we’re persisting “session_id” in the way that we should be.

For each request, Yext returns a cookie in the third-party context containing session ID, but it doesn’t match the uuid in the response. Should we be persisting the first uuid that we get back in the response and sending that with each subsequent request to Yext? I fear if we don’t, that each request, say for page 1, page 2, page 3, facet filter xyz, will be associated with a different session and not in the same session.

Documentation: Vertical Search | Hitchhikers

You can even see this in action in Yext’s own website.

Steps to Reproduce:

  1. Visit https://www.yext.com/
  2. Search “Get a Demo”
  3. Note the uuid in the response, mine was “01819152-6508-799a-017e-48c327aefa65”.
  4. Search “How can I contact sales”
  5. Note the uuid in the response, mine was “01819154-6bd0-1ae9-9f99-d64e47192651”

Even though these searches were one after another, are they not associated with the same session? Is there another mechanism that we need to use to ensure that grouped terms are associated with the same session? I would think that, in reporting, I’d want all searches within a certain period of time associated with a session id. What is Yext’s direction here?

Hi Zach! Thanks for your question.

The uuid you’re referencing in the API response is not the same as the session ID; that uuid is unique for every search that is placed. Session ID is actually captured in one of the request parameters, session_id, and also requires that you have the request parameter sessionTrackingEnabled set to true.

Best,
Alex

Thanks for jumping in @Alex_Yang1 . I’m a little confused. The following is the response from a universal query. I’ve truncated the results property to make things a little easier to read.

  1. Can you clarify the difference between the meta.uuid and the response.queryId?
  2. Which of the two should be sent in subsequent searches by a user?
  3. Which of the two is used to calculate the “Answers Sessions” metric in the Analytics report builder? I tried looking at the documentation, but couldn’t quite find the answer I was looking for.
{
    "meta": {
        "uuid": "0181a6f2-0230-7ab0-f38b-xxxxxx",
        "errors": []
    },
    "response": {
        "businessId": 2012431,
        "modules": ['...'],
        "failedVerticals": [],
        "queryId": "0181a6f2-023c-8635-6625-xxxxx",
        "searchIntents": [],
        "locationBias": {
            "latitude": 32.95526,
            "longitude": -97.01557,
            "locationDisplayName": "Coppell, Texas, United States",
            "accuracy": "IP"
        }
    }
}

Hey Zach, sure thing.

To answer your questions, neither the meta.uuid nor the response.queryId are what you are looking for for capturing session.

The meta.uuid is a unique ID we capture for every API request, and the response.queryId is captured for every “query”, which you can think of as a unique search that is placed (in the vast majority of cases, searches and API requests are 1:1; however, some searches involve multiple requests - for example, if you paginate).

Answers Sessions are captured by a different ID, which is session_id. This ID is not returned anywhere in the API response; and instead needs to be stored in sessionStorage or a session cookie, and passed in as a URL parameter when you are making the request to the query endpoint.

For example:

liveapi.yext.com/v2/accounts/me/answers/query?input=Get+a+Demo&[...]&session_id=a8abcea6-950b-4761-9002-20dbf36f2f47&sessionTrackingEnabled=true[…]

You can also see the session_id parameter in our query endpoint documentation here.

In order to store session_id in sessionStorage or in a cookie, you can follow the same instructions we have here for tracking visitor ID.

So just to summarize, we capture unique IDs for three different things:

  • Requests - These are individual API requests that are made, and is captured by meta.uuid.
  • Queries - These are unique searches that are placed, and only differ from requests when the user paginates (patination leads to multiple API requests, but only one query - because we are still only dealing with one search / result set). This is captured by response.queryId.
  • Sessions - These are collections of multiple queries that a user places before closing the page or timing out. The unique ID for this must be separately captured in sessionStorage or in a session cookie, and passed in the session_id URL param of the API request.

Hope this helps!

Best,
Alex

Sorry for my delayed response, Alex. I appreciate the depth that you went in to in your response! The documentation you’ve provided for session-tracking is very good; kudos to whoever–at this point I’m convinced it’s a small army of people–writes your guides, documentation, and training.

2 Likes

Thanks so much for the kind words, Zach! We surely couldn’t do it without experts like Alex in our corner :slight_smile: Let us know if you have any other questions!