Brand Metrics - Resolving race condition

This document addresses a specific issue related to race conditions when delivering the survey in-ad, where the publisher's ad request executes before our script has had a chance to initialize properly. This timing misalignment can result in very low render rate of the survey as we're not being able to set the key-value pair in time.

The primary recommendation to tackle this issue is to strategically adjust the execution order within your tag manager. By ensuring that our script takes precedence in the initialization sequence, you can significantly mitigate the risk of race-conditions and enhance the overall reliability of the Brand Metrics product.

The secondary solution is to implement a survey caching. How it works is that we do this by setting a localStorage item named:

__bm_c

The publisher can check if this item has any content, and if so set the targeting key themselves. The targeting key should be set to:

brandmetrics-survey=yes

When the survey is rendered or a we have got a completed retargeting- request the localStorage item is cleared.