用于 Facebook 可玩广告的 SDK [英] SDK for Facebook playable ads
问题描述
我想为 Facebook 平台制作 HTML 可播放广告并在其中显示用户头像.可能吗?
I want to make HTML playable ad for Facebook platform and show user avatar in it. Is it possible?
根据文档 可玩广告不得制作任何 HTTP 请求.
According to docs playable ad must not make any HTTP request.
所以我无法从可玩广告发出任何身份验证请求.在这种情况下,它似乎也不支持 Facebook SDK
So I just can't make any auth request from playable ad. Seems it does not support Facebook SDK either in this case
广告中的可播放代码也必须使用 JavaScript 函数 FbPlayableAd.onCTAClick()
当观众互动选择号召性用语时.
Also playable code in the ad must use the JavaScript function FbPlayableAd.onCTAClick()
when the viewer interacts chooses the call-to-action.
是否有关于 FbPlayableAd
方法的可靠文档?
Is there any reliable documentation for FbPlayableAd
methods?
推荐答案
除了您需要调用函数"之外,Facebook 似乎没有提供任何有用的信息.
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", "*");
},
};
为了绕过缺少的 FBPlayableAd
对象,这里的解决方案是在 标签之后插入以下
:
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>
然后 CTA 按钮有这个 onClick:
And then the CTA button has this onClick:
onClick={() => window.FBPlayableOnCTAClick()}
这使我们能够解决 Babel 抱怨缺少 FbPlayableAd 的问题,在测试中运行良好,并且在上传到 Facebook 的 可玩预览 工具.
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.
这篇关于用于 Facebook 可玩广告的 SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!