Wordpress and Google Analytics Events

拥有回忆 提交于 2019-12-12 05:49:12

问题


I want to track some actions in Google Analytics but I can't get it working.

I tried it with Contact Forms (Wordpress). At the additional settings I just wrote:

on_sent_ok: "ga('send', 'event', 'Formular-Beratung', 'sent');"

but it does not work. I installed the Google tag assistant, but I cant see any event (not even in the live view at Google Analytics).

Next:
There is a live chat (snapengage). Here you can also track events. For this I implemented the code

var seAgent;
SnapABug.setCallback('StartChat', function (email, msg, type) {
    seAgent = agent;
    ga('send','event','SnapEngage', 'hasChatted', email);
});

I got this from there official site: see here

This code should send an event to Google, when someone is sending a message in the chat), but nothing happens.

It seems like the whole site does not send ANY events to Google.

This is the site I am talking about. Please could anybody have a look at this?


回答1:


You need to make sure that you initialize the tracker object before you call the ga() method. You do this by placing this code at the top of the source code of your page (right after the <body> element:

<script>
  (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','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-XXXXXXXX-Y', 'auto');
</script>

Make sure to replace the UA-XXXXXXX-Y with your own property ID.



来源:https://stackoverflow.com/questions/43957553/wordpress-and-google-analytics-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!