我试图找出如何将DFP广告管理系统广告添加到我的Instant文章中。有没有人有这方面的经验? Facebook提到它是可能的,但我无法在DFP或其他任何地方看到任何文档
答案 0 :(得分:2)
根据他们的文档有两种方法。 https://developers.facebook.com/docs/instant-articles/ads-analytics。我们使用自动展示位置,我们的方法是创建一个路径来显示广告的广告(完整文档),然后通过所需的iframe src使用网址。
在您必须使用的文件的头部:
<head>
<meta property="fb:use_automatic_ad_placement" content="true">
</head>
在体内:
<header>
<figure class="op-ad">
<iframe src="your src" height="250" width="300"></iframe>
</figure>
</header>
答案 1 :(得分:1)
这是一个GPT标签示例,放在即时文章正文中:(我在Facebook帮助中尝试过这个示例,并且有很多错误)
<figure class="op-ad">
<iframe height="250" width="300">
<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
</script>
<script>
googletag.cmd.push(function() {
googletag.defineSlot('/XXXXXX/FB_Articles_300x250', [300, 250], 'div-gpt-ad-XXXXXXXXX-0').addService(googletag.pubads());
googletag.enableServices();
});
</script>
<!-- /133801272/FB_Articles_300x250 -->
<div id='div-gpt-ad-XXXXXXXXX-0'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-XXXXXXXXX-0'); });
</script>
</div>
</iframe>
</figure>
不要忘记将此行放在本文的标题中:
有一些背景的例子:
<!doctype html>
<html lang="pt-br" prefix="op: http://media.facebook.com/op#">
<head>
<meta charset="utf-8">
<link rel="canonical" href="https://yoursite/your-article/">
<meta property="fb:use_automatic_ad_placement" content="true">
<meta property="fb:article_style" content="default">
<meta property="op:markup_version" content="v1.0">
</head>
<body>
<article>
<header>
<!-- cover -->
<figure class="op-ad">
<iframe height="250" width="300">
<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
</script>
<script>
googletag.cmd.push(function() {
googletag.defineSlot('/XXXXXX/FB_Articles_300x250', [300, 250], 'div-gpt-ad-XXXXXXXXX-0').addService(googletag.pubads());
googletag.enableServices();
});
</script>
<!-- /133801272/FB_Articles_300x250 -->
<div id='div-gpt-ad-XXXXXXXXX-0'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-XXXXXXXXX-0'); });
</script>
</div>
</iframe>
</figure>
<figure>
<img src="https://yoursite/your-article/image.jpg" />
</figure>
<!-- The title and subtitle shown in your Instant Article -->
<h1>Title;</h1>
<!-- author(s) -->
<address>
Writen by <a>Author</a>
</address>
<!-- publication date/time -->
<time class="op-published" datetime="2016-08-16T17:47:42+00:00">16 ago 2016</time>
<!-- modification date/time -->
<time class="op-modified" datetime="2016-08-16T17:47:42+00:00">16 ago 2016</time>
</header>
<!-- Article body goes here (CONTINUE LIKE A NORMAL INSTANT ARTICLE) -->
答案 2 :(得分:0)
我已经在数据库中保存了DFP广告管理系统代码和“即时文章”请求。
每当我发出POST请求以将文章与Instant Articles同步时,我们就会将DFP广告管理系统标签即时嵌入到发送给IA的HTML文档中。
在开发和测试期间,我们设置了'development_mode' => 'true'
,您可以在“开发文章”部分中查看该文章。
您可以编写代码以动态生成DFP广告管理系统广告代码
/**
* Returns Array of <figure> tags enclosing <iframe> tags inside it.
*
* @param $adData
* @param $slug - Used to set targeting for restricting ads to a specific article
* @param $isInHouseArticle - Set targeting for avoiding ads for self-company article
*
* @return array
*/
private function getDFPAdCode($adData, $slug, $isInHouseArticle)
{
$DFPAds = [];
$adData = isset($adData['config']) ? $adData['config'] : [];
foreach ($adData as $ad) {
$mappings = isset($ad['mapping']) ? $ad['mapping'] : [];
$DFPAds [] = '<figure class="op-ad">
<iframe>
<script type="text/javascript">
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement("script");
gads.async = true;
gads.type = "text/javascript";
var useSSL = "https:" == document.location.protocol;
gads.src = (useSSL ? "https:" : "http:") + "//www.googletagservices.com/tag/js/gpt.js";
var node = document.getElementsByTagName("script")[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script type="text/javascript">
var targetting = {
"self-company": "' . ($isInHouseArticle ? "TRUE" : "FALSE") . '"
};
googletag.cmd.push(function() {
var googleMapping = googletag.sizeMapping();
var mappingsArray = ' . json_encode($mappings) . ';
for (var i = 0; i < mappingsArray.length; i++) {
var mapping = mappingsArray[i];
var viewport_size = JSON.parse(mapping.viewport_size);
var slot_size = JSON.parse(mapping.slot_size);
googleMapping.addSize(viewport_size, slot_size);
}
var mappings = googleMapping.build();
googletag.defineSlot("'. $ad['name'] . '", ' . $ad['sizes'] . ', "' . $ad['div'] . '").setCollapseEmptyDiv(false, false).defineSizeMapping(mappings).addService(googletag.pubads());
var url = "' . '/article/' . $slug . '";
url = url.toLowerCase();
url = url.replace(\'=\', \'_\');
url = url.substring(0,40);
googletag.pubads().setTargeting("url", url);
for (var targetKey in targetting) {
var targetValue = targetting[targetKey];
googletag.pubads().setTargeting(targetKey, targetValue.toString());
}
googletag.enableServices();
});
</script>
<div id = "' . $ad['div'] . '" style = "padding: 0px !important;">
<script type="text/javascript">
googletag.cmd.push(function() { googletag.display("' . $ad['div'] . '"); });
</script>
</div>
<div id="facebook-ad"></div>
</iframe>
</figure>';
}
$insertConfig = !empty($adData[0]['properties']) ? $adData[0]['properties']: [];
return [$DFPAds, $insertConfig];
}
您可以在创建HTML文档的同时为Instant Articles API的POST请求创建HTML文档。