Google 分析中包含(未设置)的 Facebook Instant Article

Facebook Instant Article with (not set) in Google Analytics

我是 运行 一个使用 Automattic/facebook-instant-articles-wp 的 WordPress。 但我意识到在 GA 中显示的 IA 跟踪的流量无法显示标题。

很多网站都推荐这个作为GA代码。

<script> (function (i,s,o,g,r,a,m) {i['GoogleAnalyticsObject']=r;i[r]=i[r]||function () {(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google- analytics.com/analytics.js','ga'); ga('create', 'ANALYTICS ID', 'auto'); ga('require', 'displayfeatures'); ga('set', 'campaignSource', 'Facebook'); ga('set', 'campaignMedium', 'Social Instant Article'); ga('send', 'pageview', {title: 'POST TITLE'}); </script>

然后它最终在 GA 中显示 'POST TITLE'。任何人有任何线索显示文章标题?

谢谢。

您发布的代码结尾为:

ga('send', 'pageview', {title: 'POST TITLE'});

这就是 'POST TITLE' 在 GA 中出现的原因。通过编辑此字段,您可以决定将其报告给 GA 的方式。

有一些答案可能适用于此处,但我将在此处展示需要最少修改的内容:

在你的header中:

<html <?php language_attributes(); ?>  data-title="<?php echo get_the_title();?>">

您将需要替换自己的逻辑,因为 get_the_title() 使用重写创建的某些页面将没有标题。但对于大多数用途来说,它就足够了。

<script>

            (function (i,s,o,g,r,a,m) {i['GoogleAnalyticsObject']=r;i[r]=i[r]||function () {(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),                         m=s.getElementsByTagName(o)0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-   analytics.com/analytics.js','ga');
            ga('create', 'ANALYTICS ID', 'auto');
            ga('require', 'displayfeatures');
            ga('set', 'campaignSource', 'Facebook');
            ga('set', 'campaignMedium', 'Social Instant Article');
            ga('send', 'pageview', {title: document.documentElement.getAttribute('data-title')});
</script>

由于您使用的是嵌入代码并且不确定什么是 POST TITLE,您应该尝试 document.title:

ga('send', {hitType: 'pageview', title: document.title});

有关详细信息,请参阅 page tracking。记得也将 ANALYTICS ID 更改为实际 ID。

像这样的 GA 代码应该会给你正确的标题:

<script>
 ...
ga('create', 'XX-XXXXXXXXX-X', 'auto');
ga('require', 'displayfeatures');
ga('set', 'campaignSource', 'Facebook');
ga('set', 'campaignMedium', 'Social Instant Article');
ga('set', 'title', 'IA - '+ia_document.title); // get your title 
ga('send', 'pageview');
</script>

因此 ia_document.title 您可以在分析中获得正确的文章标题。

以下是 Facebook 对该问题的引用: https://developers.facebook.com/docs/instant-articles/analytics#analytics-services

希望对您有所帮助。