Step 4: Test Context

After setup, it’s helpful to be able to test that your context rules are working end-to-end. Of course, you’ll want to test on the staging version where the site is being integrated to make sure the context is being fully passed in as coded, but in the meantime here are other options for testing the context.

Option 1: Test in CodeSandbox

Once you have your query rules set up in your Search config, do the following to test it:

  1. Set up a code sandbox that adds the search bar and sets context. You can fork this one as an example: Context + Query Rules - CodeSandbox . Replace the [[REPLACE_ME]] values with your own business ID, API key, etc.
  1. Define your context in the constant on line 17. The sandbox has the following example:

          const userData = {
            name: "ava"
          };

    Update this value to be the context you’re expecting (to align with your query rule).

  2. Save the file and experiment with conducting searches to make sure the experience reflects the query rule. Make sure to change the context to different values to test whether the rule works both when the context matches and when it doesn’t.

Option 2: Test Using Query Parameters

Another easy way to test your context rules is using query parameters. You’ll notice that when you start setting the context, the URL will update to reflect that context. Once you have your query rules set up in your Search config, test it by manually appending the context query parameter to the end of the search URL, like so:

&context={segment: "swift-fan", age: "34-55", gender: "male"}

FAQs

Does context get preserved in the URL?

Yes. Context is saved in the URL after it is used so that if users share URLs, other users will see the same results (unless context gets overwritten).

Is context passed to the search results with a redirectURL?

Yes. Context is passed from a search bar to the search results via a URL Parameter.

Does context get preserved between searches?

Yes. Context is preserved between searches and as a user navigates to vertical search. Context never changes unless it is reset.

Does setContext replace the context or add to it?

setContext replaces the existing context. You need to set the context entirely each time.

Should I pass in PII into context?

No. You should not pass PII into context. Instead pass in the segments or attributes you want to use for Query Rules (not the underlying PII).

Feedback