GraphQL: Onsite Sessions
Creating a session
When a new user comes to the app, you can use this method to get a new session. It will return you a customer-id that can save on the device and use for future requests. This would be ideal.
Updating a session
When a customer logs in, you can update the existing customer with the customer-reference. This would merge the online and mobile sessions. If not needed, I would omit this for now.
Working with recommendations
On the Product Page
In order to use the GraphQL session mutation to fetch recommendations for your search page, the event, in this case, must be VIEWED_PRODUCT
and you should specify the product-identifier of the current product being viewed.
On the Category Page
In order to use the GraphQL session mutation to fetch recommendations for your category page, the event, in this case, must be VIEWED_CATEGORY
and you should specify a fully qualified category path of the current category. For example, if you have a category called "Dresses" under the category "Women", the FQCN would be "/Women/Dresses".
On the Search Page
In order to use the GraphQL session mutation to fetch recommendations for your search page, the event, in this case, must be SEARCHED_FOR
and you should specify the search term of the query.
On the Cart Page
In order to use the GraphQL session mutation to fetch recommendations for your cart or checkout page, the event, in this case, must be VIEWED_PAGE
and you should specify a fully qualified URL of the page as the target.
On the Front Page
In order to use the GraphQL session mutation to fetch recommendations for your home or front page, the event, in this case, must be VIEWED_PAGE
and you should specify a fully qualified URL of the page as the target
Attribution of Recommendation Results
Recommendation results can be attributed to events by setting a session event's ref
to the recommendation result's resultId
.
Here is an example of some recommendations for a front page. You can see recommendation result's resultId
is "frontpage-nosto-1"
.
If a customer selects to view the Cool Kicks product, you can generate the following request. Note that the event's ref
is set to "frontpage-nosto-1"
.
GraphQL from mobile applications
When making GraphQL queries from mobile applications, it's essential to define the user agent string in your HTTP headers. Ideally, the user agent should represent the mobile environment, including details such as the platform, device type, and application version. Avoid using terms like "bot" in the user agent string, as this might lead to unintended behavior or rejection of the query/session. Sending an empty user agent will also lead to be catch by the bot detection mechanism.
Last updated