SDK for Facebook playable ads

Viewed 2035

I want to make HTML playable ad for Facebook platform and show user avatar in it. Is it possible?

According to docs playable ad must not make any HTTP request.

So I just can't make any auth request from playable ad. Seems it does not support Facebook SDK either in this case

Also playable code in the ad must use the JavaScript function FbPlayableAd.onCTAClick() when the viewer interacts chooses the call-to-action.

Is there any reliable documentation for FbPlayableAd methods?

1 Answers

Facebook doesn't appear to offer any helpful information beyond "you need to call the function".

When a playable is served, this <script> is injected into the <head>:

  const FbPlayableAd = {
    onCTAClick() {
      window.parent.postMessage("onCTAClick", "*");
    },
  };

To get around the missing FBPlayableAd object, solution here was to insert the following <script> after the <body> tag:

<script type="text/javascript">
window.FBPlayableOnCTAClick = () => { 
  (typeof FbPlayableAd === 'undefined') ?
    alert('FBPlayableAd.onCTAClick') : FbPlayableAd.onCTAClick();
}
</script>

And then the CTA button has this onClick:

onClick={() => window.FBPlayableOnCTAClick()}

This allowed us to clear issues with Babel complaining about the missing FbPlayableAd, works fine in test, and functions fine when uploaded to Facebook's Playable Preview tool.

Related