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.
最合适的回答,由SO网友:TheDeadMedic 整理而成
如果要内联打印脚本(即不在外部文件中),可以使用PHP动态输出JavaScript参数:
<script>
_gaq.push( \'setCustomVar\', 3, \'pubDate\', \'<?php the_time( \'Ym\' ) ?>\', 3 );
</script>
请参见
PHP manual for date arguments, 这就解释了我为什么
Ym
.