How to test the relevance CookieCollector

Hello all,
I have configure the relevance cookiecollector. But this collector does not come with a ui or out of the box charactaristic. So I was wondering, how can I test/access this cookiecollector and the data it collected.

I am also trying to use the Expression Inference rule engine. Can I use the data of this collector there ?

Hi @Mijnisha ,

To test and access the data collected by the relevance cookiecollector, you can follow these steps:

  1. Accessing the Collected Data:
  • The data collected by the cookiecollector can be accessed through the targeting data available in the request context. You can use the TargetingStateProvider to get the profile and then retrieve the targeting data. Here is an example code snippet:
TargetingProfile profile = TargetingStateProvider.get().getProfile();
Map<String, TargetingData> targetingData = profile.getTargetingData();
InferenceGoalsTargetingData inferenceGoalsTargetingData = (InferenceGoalsTargetingData) targetingData.get("inferencecollector");

Java

  • Ensure that you handle the data correctly to avoid class cast exceptions. The targeting data should be cast to the appropriate type.
  1. Using the Data in the Expression Inference Rule Engine:
  • The data collected by the cookiecollector can be used in the Expression Inference Rule Engine. You can set the value of the cookie in the extra data targeting map within your inference rule expression. This value can then be used to set attributes on the request context, which can be utilized in your Freemarker templates or other components.

  • Here is an example of how you might set the value in the extra data targeting map:

// In your inference rule expression
extraData.put("cookieValue", cookieValue);

Java

  • You can then retrieve and use this value before rendering your components.
  1. Testing the Collector:
  • To test the cookiecollector, you can simulate requests with the relevant cookies and verify that the data is being collected and stored correctly. You can use tools like Postman or browser developer tools to set cookies and inspect the requests and responses.
  • Additionally, you can log the collected data to ensure it is being captured as expected.

By following these steps, you should be able to test and access the data collected by the cookiecollector and use it within the Expression Inference Rule Engine.

Kindly please let me know if this helps ?

Thanks and Regards,
Rajesh S