How to get user surfing statistics?

2019-09-05 17:22发布

问题:

This question is connected with Get user data collected by Google tag manager in order to make it more concrete.

I have a Ruby-on-Rails web application. Assume, that some user comes to my site, surfs several pages and then sends me a feedback through feedback form. Is there any way to gather such information like:

  • which keywords led user to my site
  • what pages did he visited on my site and for how long
  • any other surfing statistics, that could be interesting

in order to send it together with this feedback?

I have a Google Tag Manager which gathers such information but it sends automatically to my google account and I can't find any API to get it in order to attach to feedback.

回答1:

First, you have to think that google analytics has the data, so the first question is how to extract google analytics' data ? You can use Google analytics API, see here on implementation details : How to pull Google Analytics stats?

The question then is what data to send to google analytics to be able to identify data for a specific user ? Well, that's simple, just send the user id. But ... you can't because it's not allowed by google analytics. BUT you CAN send a HASHED user id. So what you can do is send a custom dimension hashed user id and also have a custom dimension Page Type which takes the value "feedback". Then if you want to know things such as the session duration per user who went to feedback you can do:

Dimensions : Hasher user id
Metrics : session duration
Filters : 'Page Type' exact 'feedback'

It will return something like :

Hashed user id | duration
eoqi456dsa46wc |   time1
hashed9877ad8c |   time2

Edit : To send the user id, you have to include this javascript snippet: ga('set', 'hashed_user_id', <%= current_user.id %>);

So maybe your view for your feedback will be something like this:

<script>
  ga('set', 'hashed_user_id', <%= current_user.id %>);
  ga('set', 'Page Type', 'Feedback');
  ga('send', 'pageview');
</script>

<%= render 'feedback/form' %>

Please note that if you want to track people who ANSWERED the feedback then you might want to put ga('set', 'Page Type', 'Feedback answered'); for instance and put the jascript on the success page.



回答2:

Do you have a Google Analytics account set up? Just adding Google Tag Manager (GTM) code to your site will not collect any data. GTM is just a container. When there's a hit on a page that has the GTM code, the tags within the container are fired according to firing rules that you have created.

In order to get Google Analytics data, you have to first set up a Google Analytics account (http://analytics.google.com/), then create a new property. When you create the property, you'll get a UA code that you can use in GTM by adding a new tag (Universal Analytics) and set it to track pageviews.

Then enter the UA code in the tag setup page and set it to fire on "All Pages".

In a few hours, data should start showing up in your Google Analytics reports.

Link to GTM screenshot