谷歌分析

发布于 2024-12-29 05:59:06 字数 961 浏览 3 评论 0原文

我有一个问题,我可以让跟踪正常工作,但我似乎无法让事件正常工作。

我们有一个 DNN 网站,其中包含我们的在线会员服务,用户可以选择成为新会员,然后开始会员申请流程。编写此代码是为了在每个步骤中交换所需的控件,因此对于所使用的 7 个不同控件,URL 不会更改。这给我们带来了无法跟踪页面的问题。

因此,有了这样的背景,我认为我们可以使用甚至跟踪来代替。不,也许我没有正确设置它,所以这里是以下代码。

<script type='text/javascript'>
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-28551246-1']);
        _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>

这是标准帐户信息和设置脚本。我正在尝试跟踪谷歌页面上的以下示例

<button onclick="_gaq.push(['_trackEvent', 'button3', 'clicked'])"></button>

任何帮助都会很棒。

I have a problem where I can get tracking to work fine, however I cannot seem to get events to work.

We have a DNN website that contains our Online Member Services, the user has the option to be a new member which starts the membership application process. This has been written so that it swaps in the required controls for each step, so the URL doesn't change for the 7 different controls used. This causes us the issue that we can't track the pages.

So with that general background, I thought we could use even tracking instead. No perhaps I haven't correctly set this up, so here is the following code.

<script type='text/javascript'>
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-28551246-1']);
        _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>

which is the standard account info and setup script. I'm trying to track given the folling example on the googles pages

<button onclick="_gaq.push(['_trackEvent', 'button3', 'clicked'])"></button>

Any assistance would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

北渚 2025-01-05 05:59:06

有类似的问题。您可以使用以下内容附加到 URL:

window.location.hash = '#/' + pageNumber;

然后在 GA 中使用它:

_gaq.push(['_trackPageview', location.pathname + location.search + location.hash]);

Had a similar problem. You could append to the URL using something like:

window.location.hash = '#/' + pageNumber;

and then use this in GA:

_gaq.push(['_trackPageview', location.pathname + location.search + location.hash]);
ˇ宁静的妩媚 2025-01-05 05:59:06

我同意 trackPageView 是更好的方法,因此您可以在页面报告中看到它们。我假设您没有重新加载页面,这就是您仍然需要单击事件的原因。如果是这样,您可以执行类似的操作

function whenUserChangesControls (controlIdentifier) {    
   _gaq.push(['_trackPageview', '/control"+controlIdentifier ]);    
}

或任何您想要的页面名称。但请确保它是唯一的,否则如果您提供的名称与现有页面名称匹配,GA 会将其添加到页面的聚合中。
然后,您只需在用户导航您的页面时使用 onclick="whenUserChangesControls(cI)" 即可。

请记住,在 GA 的页面浏览量报告中,您现在将看到每个页面浏览量都是独立的页面浏览量。

关于trackEvent代码,看起来不错,错误一定是在其他地方。

I agree that trackPageView is a better way to go, so you can see them in the pages report. I assume though that you are not reloading the page, and that is why you still need the click event. If so, you can do something like this

function whenUserChangesControls (controlIdentifier) {    
   _gaq.push(['_trackPageview', '/control"+controlIdentifier ]);    
}

or whatever you want as the name of page. Make sure it is unique though, otherwise GA will add it to the aggregation of the page if the name you provided matches an existing page name.
Then, you just use onclick="whenUserChangesControls(cI)" as a user navigates your page.

Remember that in your pageViews report in GA you will now see each one of them as an independent page view.

Regarding the trackEvent code, it looks good, the error must be somewehere else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文