【问题标题】:Facebook Instant Article with (not set) in Google Analytics在 Google Analytics 中使用(未设置)的 Facebook Instant Article
【发布时间】:2016-11-23 20:11:13
【问题描述】:

我正在运行一个使用 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”。有人有任何线索显示文章标题吗?

谢谢。

【问题讨论】:

  • 你把这段代码放在你的主题中的什么地方?
  • @Dan9 在插件的分析嵌入代码部分。

标签: wordpress facebook google-analytics facebook-instant-articles


【解决方案1】:

这样的 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

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    您发布的代码以:

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

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

    【讨论】:

    • @J Brazier Opps。非常抱歉。我会说。如何更改文章标题?
    • @CarsonLee 编辑 Javascript 以在此处插入文章标题,而不是文本字符串 'POST TITLE'
    • @J Brazier Cool。你能展示一下javascript应该是怎样的吗?谢谢!!
    【解决方案3】:

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

    在您的标题中:

    <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>
    

    【讨论】:

      【解决方案4】:

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

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

      请参阅page tracking 了解更多信息。记得把ANALYTICS ID也改成实际ID。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-29
        • 1970-01-01
        • 2017-08-16
        • 2017-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多