Setting targeting too late

In some cases, targeting key-values are set too late, after the ad request has already been sent to GAM.

This problem occurs most frequently in two situations

  • Upon user navigation within Single Page Apps
  • When page metadata is loaded asynchronously from an external data store, separately from the page content

Detecting the problem

This problem is most easily detected by directly inspecting the ad requests that are sent to GAM. The cust_params field contains page-level targeting key-values. If the expected key-values are absent, this means that targeting is being set in time.

image

Is targeting being set “too late” or “not at all”?

To distinguish between these cases.

  1. Load your webpage
  2. Verify that cust_params is missing the expected key-values
  3. Then type in the console googletag.pubads().refresh()

This will reload all the ads by issuing another HTTP Request.

Finally, inspect the 2nd ad request.

If the expected key-values in cust_params are absent from the 1st request, but present in the 2nd request, this means targeting is working, but the function call occurs too-late, after the initial ad request has been sent to GAM.

If the expected key-values in cust_params are absent from BOTH requests, this means that targeting is not working. Check for syntax errors, add logging, or set a breakpoint to verify that the setTargeting() function is being called.