Step 4: Setting Click Tracking Dynamically
Once click tracking is turned off by default, you have two options. The first is to simply keep it off — however, we strongly recommend against this.
Similar to session tracking, a better option is to toggle click tracking dynamically based on whether the user has consented to it. The mechanism to do this will change based on how you are integrating.
Search HH Theme Integrations
Use the runtimeConfig
to turn on click tracking.
If you are using the JS Snippet option, call:
AnswersExperienceFrame.runtimeConfig.set("analyticsEventsEnabled", true)
If you are using a subdomain, call:
AnswersExperience.runtimeConfig.set("analyticsEventsEnabled", true)
Search UI SDK Integrations
Use the ANSWERS.setAnalyticsOptIn
hook:
ANSWERS.setAnalyticsOptIn(true)
Examples
Here is an example of how you might accomplish this with a simple HTML checkbox. This can be extended to integrate with any cookie consent management system.
<label>
<input
type="checkbox"
onChange="ANSWERS.setAnalyticsOptIn(this.checked);"
/>
I consent to the cookie policy.
</label>
In this example, when the user checks the check box, it calls the ANSWERS.setAnalyticsOptIn
hook to update analyticsEventsEnabled
. It passes true
if the box is checked, and false
if it’s not. In turn, this stops any clicks from being recorded.