向Google Analytics推送类别和发布日期

时间:2015-04-24 作者:Revious

I have found an interesting article about tracking variables with JS based statical system (for example Google Analytics).

The article writes examples like:

_gaq.push(\'setCustomVar\', 3, \'pubDate\',\'YYYYMM\',3);
_gaq.push(\'setCustomVar\', 4, \'contCat\',\'[CATEGORY NAME]\',3);
_gaq.push(\'setCustomVar\', 5, \'contSubCat\',\'[SUB CATEGORY NAME]\',3);

But how can I get the actual value of the pubdate from the PHP environment of Wordpress and write it in the HTML generated code so that it will be really made available to analytics? I hope the question is clear enough.

1 个回复
最合适的回答,由SO网友:TheDeadMedic 整理而成

如果要内联打印脚本(即不在外部文件中),可以使用PHP动态输出JavaScript参数:

<script>
    _gaq.push( \'setCustomVar\', 3, \'pubDate\', \'<?php the_time( \'Ym\' ) ?>\', 3 );
</script>
请参见PHP manual for date arguments, 这就解释了我为什么Ym.

结束

相关推荐

Wordpress global variables?

我有一个叫“某物”的metabox页面。它可以有两个值“value”和“value2”。我在这个页面上使用了一个短代码,希望它显示一些东西的值。问题是我不知道如何在短代码中访问全局变量?例如,我在第页有这个。php:if($something == \"value\") { global $one, $two; $one = 120; $two = 240; } 现在我想在shortocde(functions.php文件)中