prebid / prebid-universal-creative

Apache License 2.0
43 stars 69 forks source link

Add macro to track clicks #196

Closed musikele closed 1 year ago

musikele commented 1 year ago

In a GAM native ad, if you prepend %%CLICK_URL_UNESC%% to links, GAM will also track clicks.

To use it, the publisher must change the Prebid Universal Creative script like this:

<script>
  var ucTagData = {};
  ucTagData.adId = "%%PATTERN:hb_adid%%";
  ...
  // if you're using GAM and want to track outbound clicks on native ads you can add this line
  ucTagData.clickUrlUnesc = "%%CLICK_URL_UNESC%%";
  ...
  try {
    ucTag.renderAd(document, ucTagData);
  } catch (e) {
    console.log(e);
  }
</script>

In the native template code, publisher can prepend this macro to their hb_native_linkurl:

<div>
   ...
   <a href="%%CLICK_URL_UNESC%%##hb_native_linkurl##" target="_blank" />
</div>

This PR tries to support many scenarios: