我试图让我网站上的作者通过在 Analytics 中设置一个 channel 并通过他们的个人资料提交来检索他们自己的 Google 分析数据。我已经尝试了很多方法来做到这一点,但这是迄今为止我所拥有的。
window.google_analytics_uacct = "UA-xxxxxxx-xx";<script type="text/javascript">//<![CDATA[
var _gaq = _gaq || [];
_gaq.push(['_setAccount','UA-xxxxxxx-xx']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setAccount', 'UA-xxxxxxx-xx']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
//]]></script>
我试图将以下 PHP 合并到推送到的第二个帐户数据中。
<?php if ( get_the_author_meta( 'analytics' ) ) { ?>
<?php the_author_meta( 'analytics' ); ?>
<?php } ?>
我在第二组周围使用了 if 语句
_gaq.push(['_setAccount', 'UA-xxxxxxx-xx']);
_gaq.push(['_trackPageview']);
仅当网站作者提交了其 Analytics ID 时才显示此集。
不幸的是,仅仅从数据库获取值本身就给我带来了很多问题!任何帮助将不胜感激:)
亲切的问候
奥利
最佳答案
-试试这个。作者元“分析”必须类似于 UA-1234567-12
<script type="text/javascript">//<![CDATA[
var _gaq = _gaq || [];
_gaq.push(['_setAccount','UA-xxxxxxx-xx']);
<?php if($ganal = get_the_author_meta('analytics')): ?>
_gaq.push(['_setAccount', '<?php echo $ganal; ?>']);
<?php endif; ?>
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
//]]></script>
关于php - 多作者 Google Analytics(将 PHP 变量从 DB 组合到 JS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6013311/