How to Test Context with Answers End-to-End

This works great! We used the code sandbox to text context + query rules for a client who wanted to show different content for prospects than for existing customers.

We set the context in the sandbox like this:

<script>
      const context = {
        is_prospect: false
      };
    </script>

And then toggled “is_prospect” from “false” to “true” to test the rules. Here is an example of two query rules we set up to show different content when a prospect searches “basics” than when an existing customer searches “basics”:

{
  "criteria": {
    "contextMatches": {
      "$.is_prospect": {
        "$eq": true
      }
    },
    "searchTermContains": "basics"
  },
  "actions": [
    {
      "actionType": "BOOST_ENTITIES",
      "entityIds": [
        "promotiongetstarted"
      ],
      "verticalKey": "Promotion"
    }
  ]
},
{
  "criteria": {
    "contextMatches": {
      "$.is_prospect": {
        "$eq": false
      }
    },
    "searchTermContains": "basics"
  },
  "actions": [
    {
      "actionType": "BOOST_ENTITIES",
      "entityIds": [
        "promotiongetstartedwebinar"
      ],
      "verticalKey": "Promotion"
    }
  ]
},