谷歌分析没有正确跟踪事件。

时间:2021-09-23 03:55:37

I'm using google analytics (analytics.js) to track a couple of buttons and facebook and twitter for social part but the problem is since the last Saturday that I configured the analytics code, can't see my events registered in my dashboard and it's strange because If I open the developers console of Chrome or Firefox can see the request and is returning 200 OK so, I don't know what's the exactly error.

我使用google analytics(analytics.js)跟踪几个按钮和facebook和twitter社会一部分但问题是自上周六我配置分析代码,看不到我的事件注册我的仪表板和很奇怪因为如果我打开开发人员控制台Chrome和Firefox可以看到请求和返回200好了,我不知道到底是什么错误。

Index.html

index . html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

<a href="#" id="my_button">My button</a>
<a href="#" id="my_facebook_button">My Facebook Button</a>
<a href="https://twitter.com/intent/tweet?text=My tweet body!&url=http://mywebsite.com"></a>

<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId      : 'XXXXXXXX',
            xfbml      : true,
            version    : 'v2.2'
        });

        //Track FB Share function
        FB.Event.subscribe('message.send', function(targetUrl) {
            ga('send', {
                'hitType': 'social',
                'socialNetwork': 'Facebook',
                'socialAction': 'Share',
                'socialTarget': 'http://giftagiftcard.com'
            });
        });    

    };
</script>
<script src="jquery.js"></script>
<script src="main.js"></script>
<script>
    // Google analytics
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-58646812-1', 'auto');
    ga('send', 'pageview', {
        'hitCallback': function() {
            console.log('Analytics is sending data');
        }
    });

    //Twitter Web Intents
    window.twttr = (function (d,s,id) {
        var t, js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
        js.src="//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
        return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
    }(document, "script", "twitter-wjs"));

    //Track twitter tweets
    function trackTwitter(intent_event) {
        if (intent_event) {             
            ga('send', {
                'hitType': 'social',
                'socialNetwork': 'Twitter',
                'socialAction': 'Tweet',
                'socialTarget': 'http://mywebsite.com/'
            });
        }
    }


</script>
</body>
</html>

main.js

main.js

$(function() {

$('#my_button').on('click', function(e) {
    e.preventDefault();

    ga('send', 'My button', 'button', 'click', 'My button!');

});

$('#my_facebook_button').on('click', function(e) {
    e.preventDefault();

    FB.ui({
        method: 'feed',
        name: 'The name',
        link: 'http://mywebsite.com',
        picture: 'http://thepicture.png',
        caption: 'The caption',
        description: 'The description'
    },
        function(response) {
        }
    );
});

});

Actually, Facebook and twitter open the popup to share or tweet but facebook is not detecting the FB.Event.subscribe.

事实上,Facebook和twitter打开了popup分享或tweet,但Facebook并没有检测到FB.Event.subscribe。

So, my errors are:

所以,我的错误是:

  • I don't know if my GA events are wrong but the request return 200 OK and I can't see the events in my dashboard.
  • 我不知道我的GA事件是否错误,但是请求返回200 OK,我无法看到仪表板中的事件。
  • Facebook is not detecting the Event.subscribe to once the user share, record the event
  • Facebook没有检测到这一事件。订阅用户共享,记录事件。

I hope someone knows what are the issues with my code. Thank you in advance.

我希望有人知道我的代码有什么问题。提前谢谢你。

2 个解决方案

#1


0  

This line, in your main.js, looks off:

这条线,在你的主轴上。js,看起来:

 ga('send', 'My button', 'button', 'click', 'My button!');

"My button" doesn't look like a GA method like 'event'.

“我的按钮”看起来不像“event”这样的GA方法。

#2


0  

You can use the Google Analytics Debugger plugin - very useful

您可以使用谷歌分析调试器插件——非常有用。

#1


0  

This line, in your main.js, looks off:

这条线,在你的主轴上。js,看起来:

 ga('send', 'My button', 'button', 'click', 'My button!');

"My button" doesn't look like a GA method like 'event'.

“我的按钮”看起来不像“event”这样的GA方法。

#2


0  

You can use the Google Analytics Debugger plugin - very useful

您可以使用谷歌分析调试器插件——非常有用。