多作者 Google Analytics(将 PHP 变量从 DB 组合到 JS)

发布于 2024-11-07 18:18:47 字数 1191 浏览 0 评论 0原文

我试图让我网站上的作者通过在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮筵 2024-11-14 18:18:47

-试试这个。作者元“分析”必须类似于 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>

-Try this one. Author meta 'analytics' must be like 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文