Configuring User Segmentation in the Google Analytics Module for Drupal 6.x

Posted Date: 
Tue, 04/07/2009

In this video we will be learning about:
  - How User Segmentation can enhance Google Analytics reports
  - Format of the "User Defined Variable"
  - Using Regular Expressions to create Custom Segments
  - Creating a Google Analytics report using Custom Segments

The Google Analytics module for Drupal 6.x integrates Drupal's powerful site administration tools so you can harness the fullest potential of your Google Analytics account.  The module offers user-specific, role-specific, and page-specific tracking.  It can send role or profile information to Google Analytics so you can run user segmentation reports.  You can easily extend your Google Analytics with custom JavaScript code.  The possibilities are endless!

 

Primary Screencast: 
Syndications

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

User Defined Variable?

Hi Brian,

Great Videos! Can you help me trouble shoot this really quick?

I have the latest version of the Google Analytics module installed on my site and it has been tracking basic stats for a few months now.

Some background:

- On the module side I have two roles selected to add tracking - Anonymous and Publisher
- I have user segmentation set for user roles only
- I have use PHP for tracking visibility selected under permission for all roles
- all roles are tracked (no opting out)
- Analytics is functioning

The Issue/Problem:

I'm trying to segment by the two roles.

I'm trying to follow your video, but when I go into my analytics account and try and create a new advanced segment I don't see any roles or anything showing up in the value field. I'm putting the "user defined value" green box into the "dimension or metric" box and selecting "contains" for the condition. Nothing is showing up in the value field. Do I need to define these from scratch? In your tuturial they autocomplete as you type Columbus.

Am I missing something or do I have a glitch?

Thanks a bunch,

Matt

great question about user segmentation

Can you double check something for me?
Under the User Segmentation section of Google Analytics, you should have a listbox labeled Add segmentation information to tracking code:
In that box, you should have an option called "User Roles" and a list of profile field names if you've enabled the Profile module (optional in your case).  In order to get the user role infomation into Google Analytics, you'll need to explicitly click on "User Roles".  If it is already selected, and nothing is still being sent to GA, we'll have to look into some more potential problems.
Let me know.  :-)
Peace,
Brian

Thanks for the excellent

Thanks for the excellent videos on the GA module!

It seems that the profile module must be enabled for user segmentation to work. I set up everything as mentioned in the video but did not enable the profile module and I got no values in the GA "user defined value" field, and the Javascript code added at the bottom of each page did not set any values. I then simply enabled the Profile module and immediately the Javascript code contained the following:

_gaq.push(["_setVar", "authenticated user,administrator user"]);

I have not seen the values appear in GA yet (likely have to wait a day), but hopefully this means that the user segmentation will now work as described in your video.

Hi Brian, Thank you very much

Hi Brian,

Thank you very much for a great tutorial. Unfortunately, I am having a problem selecting my user roles in Google Analytics. I tried to follow what you wrote above, but I cannot find the User Segmentation section in Google Analytics. Would you be able to provide me with a little more information on finding this section?

Thanks again,
Paul

did you enable the Profile module?

Are you referring to User Segmentation settings in google.com or User segmentation settings within the Drupal module itself?

Well, actually I am not quite

Well, actually I am not quite sure. lol. In Google Analytics I tried to create an advanced segment using the User Defined Value dimension just as you did in the video. However, no matter what condition I select the only value options I have are "authenticated user,site administrator" and "(not set)" I have two other roles defined in my drupal site that are not appearing as options.

In drupal under "User specific tracking settings" I have Track users by default, but let individual users to opt out and for "Role specific tracking settings" I have anonymous and my two other roles checked. Only the site adminstrators have permission to opt out. I also have User roles selected under "User segmentation settings. It looks like it should work, but perhaps I am missing something.

I do not have the profile module enabled since the accounts are private. Is this a requirement?

Thanks for you time,
Paul

ok, i think I know what is going on

Since you're able to see (not set) and "authenticated user,site administrator" in your google analytics reports, then we know that drupal is correctly talking to google (profile module is not required).
I suspect the problem could be one of two things:
1. You recently enabled the reporting of roles within your module.  Simply not enough data has been collected.  In other words, no one from those other two roles has logged into your site.  Google only populates that list from what it knows from past visitors.
2. Try simplifying your settings:  Check "authenticated users", and "anonymous users" under the "Add tracking for specific roles" section (w/ all other roles unchecked). And, check "Track users by default, but let individual users to opt out." in the "custom tracking settings".

I think reason 1 might be it.

I think reason 1 might be it. I will give reason 2 a try to see if that works. Thank you very much for your assistance.

Paul

Problem with the user variable

I am pretty much having the same issue that the first poster in this thread mentioned.

I do have User Roles marked in the 'Add segmentation information to tracking code:' box and I do have the three user roles that I want to track all checked in the 'Role specific tracking settings:
Add tracking for specific roles: " settings.

Any other suggestions as to what it will take to have the values appear in the User Defined box on the Seg Report?

glitch

I think that is a glitch with GA.  I noticed that one day it didn't autocomplete for me, yet the segment worked.  Then I went back in there a different day and it did autocomplete. 

Problem with the user variable

I have been trying for three days now. I suspect it is something other than a GA glitch. I do have a new option in the dropdown box though. In addition to I also have :: as an option.

Same problem

Hi Brian! Seems I have exactly the same problem. Base conditions are same as mentioned above except of user segmentation. I want to segment anonymous and authenticated users. Can't see anything in Value field in GA.

I have that clicked

Hi Brian,

I have user roles selected.

I emailed you a screenshot.

-Matt

Google Analytics Videos

Hi Brian,

I am trying to learn Drupal. I was exactly looking to know about how to use Google Analytics with Drupal. Just watched all your 4 videos. Your language was very lucid and I found it very helpful. Without reading any thing, I believe now, I have enough knowledge about what I wanted. Thank you very much for the videos.

In the same, do you have other videos where you try to disucss the various concepts ( from some what medium level to advanced code level such as writing PHP code and using it in the Drupal framework ) for web development. I would very glad if you already some good number of videos.

Please let me know.

Thanks and Regards,
Sivaraman

great tutorial

It was very userful for me. Thank you.

Great video

Brian,

Great video, although I am not a drupal user, the instruction on the GA user segmentation reports was very useful.

Thanks!

thanks jon!

I'm glad this video helped you with User Segmentation. I was thinking something very similiar shortly after producing this video, "Wow, I bet this would be help non-Drupal users too." :-)

I have tried it,,,

I have tried it twice but I can't still make it. I am just a newbie of using google analytics too.What would I do?

Brian, After doing some more

Brian,

After doing some more research, I have come to understand that this user segmentation method probably will not work for my needs. It seems the cookie sent to GA with the _setVar method (User Defined Variable) will remain with the user for each page they view during that particular visit.

What I want to be able to do is gather metrics based on a user's page views or form submission. For example, if a user selects productid 1, producttype 2 and productcode 3 I want to be able to see how many users selected 1,2,3 vs. how many selected 2,3,4 etc...

I don't think filters will help much either. A filter results in storage of aggregrate data and I want to be able to filter the raw data in whatever combination of values my heart desires at the time I am examining the data.

Is there a way to publish pageview data to GA and then be able to query that data in much the same way that your video describes with user segmentation reports and regular expressions?

Use _trackEvent

You will probably have more success using the _trackEvent function.

Check out this page for more information: http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html

If this is a shopping cart, you could have the "Add To Cart" link formatted link this:

<a onClick="pageTracker._trackEvent('Shopping Cart', 'Add to Cart', 'Product Description or Product ID', 'Dollar Value of Product - Integers only!');" href="some url...">Add to Cart</a>

These click events can be tracked in the events section:
https://www.google.com/analytics/reporting/events

Thanks Brian. Any chance you

Thanks Brian. Any chance you could point out how I would use the Gender field in a profile to show a report based on male and female? The expression is a wee bit confusing.

Does this look right?

(^|,)(male)(:|,)

close...

That regular expression would work well if you had a role named "male". Instead, you will want a regular expression that looks more like:

:(male)$

This above expression will only work if:
1. The gender data is all lowercase. (male vs Male vs MALE)
2. The gender field is the first, and only, profile value you are sending to Google Analytics.

If you can reply back with an example of an entire user defined variable, I can help you craft an appropriate regular expression.

I'm having an odd issue

I'm having an odd issue between Google Adwords and Google Analytics. I
have multiple Adwords accounts and multiple Analytics accounts
(obviously all for different websites). However, when I connected the
first Adwords account with an Analytics account, it filled in CPC data
for all of my Analytics accounts - so they all show the same Adwords
data, even though it is only correct for one of my accounts.
Any thoughts on fixing this? I'm not sure I even know where to begin.
Anyone else having this problem?
live croupiers

check out these google pages.

check out these pages:
http://www.google.com/support/googleanalytics/bin/answer.py?answer=92625&ctx=sibling
http://www.google.com/support/googleanalytics/bin/answer.py?answer=55613
I wonder if you are doing any advanced javascript to link your domains together.  I believe you can share the google analytics cookie between multiple domains.  that could be throwing things off:
 

_setDomainName("none");
_setAllowLinker(enable);
_setAllowHash("false");
_link();
_linkByPost();
 
  

Analytics across sub-domains

First of all Brian, you rock, i learned more about google analytics in this video than I have in years.

Two questions for you;
1) Is a custom reporting system even necessary if you can customize drupal/GA to this extent in your experience?

2) Can you point me to documentation that shows how to enable tracking across sub-domains? The tracking code for the drupal module spits out the JS code automatically, any references I've found to sub-domain tracking has been a javascript snippet off the GA site, but obviously that would require adding this manually, and that's not an option!

Thanks!

Thanks Lu!

Thanks Lu!  :-)
I personally don't use a custom reporting system now that I'm using Google Analytics.  And, GA recently introduced a very nice Custom Reports ability so I can customize my GA reports if I have particular requirements.
As for enabling user tracking across subdomains, check out my other video:
http://www.brianstevenson.com/drupal/screencasts/advanced-googleanalytics3
No PHP programming is needed, you just need to add one line of javascript into the module's admin interface.  It's a piece of cake.
Peace,
Brian

Thanks!

Thanks so much for posting this it's exactly what I was looking for!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Subscribe to Drupal Screencasts (RSS)