多作者 Google Analytics(将 PHP 变量从 DB 组合到 JS)
我试图让我网站上的作者通过在 Analytics 中设置一个频道并通过他们的个人资料提交来检索他们自己的 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']);
以便仅在网站作者提交了其分析 ID 时才显示该组。
不幸的是,仅仅从数据库获取值本身就给我带来了很多问题!任何帮助将不胜感激:)
亲切的问候
奥利
I am trying to let authors on my site retrieve their own Google analytics data by setting up a channel in Analytics and submitting it via their profile. I ahve been trying plenty of ways to do this, but here is what I have so far.
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>
I was trying to incorporate the following PHP around the second account data is pushed to.
<?php if ( get_the_author_meta( 'analytics' ) ) { ?>
<?php the_author_meta( 'analytics' ); ?>
<?php } ?>
I was using the if statement around the second set of
_gaq.push(['_setAccount', 'UA-xxxxxxx-xx']);
_gaq.push(['_trackPageview']);
With the view of only displaying this set if the site author has submitted their Analytics ID.
Unfortunately just getting the value from the database in itself is causing me a lot of problems! Any help would be appreciated :)
Kind Regards
Oli
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
-试试这个。作者元“分析”必须类似于 UA-1234567-12
-Try this one. Author meta 'analytics' must be like UA-1234567-12