Hi,

This may be a big ask, but I was wondering whether this module could be used by all users on a site to track their nodes with Google Analytics? So basically each user could see various stats, but only for nodes that they have authored?

Thanks to anyone who can point out whether this is possible.

Comments

wqmeng’s picture

+1 will look into it soon

Jboo’s picture

Great, thanks. I'm looking forward to seeing if this can happen.

wqmeng’s picture

The permission to view the Google Analytics Report need to be 'administer google analytics settings'. So to view the report to a user, you need to add the 'administer google analytics settings' permission to the user.

While it is obviously that a normal user should not be assign a 'administer' permission to them. I think it is a bug of the permission checking with the view report system.

I will report a possible bug to the maintainers to get the problem fix.

thanks

raspberryman’s picture

Assigned: Unassigned » raspberryman
Status: Active » Postponed

We're heading in this direction, but our new rewrite will have a much tighter focus for v1.0. Stay tuned, but don't plan on this in the near future.

grendzy’s picture

Project: G̶o̶o̶g̶l̶e̶ A̶n̶a̶l̶y̶t̶i̶c̶s̶ A̶P̶I̶ (obsolete) » Google Analytics Reports
Version: 6.x-1.0-alpha1 »
SWMdave’s picture

Version: » 6.x-1.0-beta1

I need help getting data to print into a block or node. I seem do be able to get charts to work from the sample, but I can't print data into a standard html table or set of divs. I am posting here because I intend to create a node and print this data into it (basically you can use the api and filter down to specific content)and limit its view by user. With the Google API, if you attach a filterable parameter to each users content then I believe it will be possible to filter the content like mentioned above and use either an individual node permission module (which there is a very good one) or add a simple "if, then" that rotates the analytics data based on user id so they can only see data that matches the individual user id.

grendzy’s picture

Hi, formatting the HTML is up to you, but you can use dpm() to inspect the query result. You can loop through the array and print whatever HTML you need. theme('table') can help simplify rendering a table.

$feed = google_analytics_api_report_data($params);
dpm($feed);
SWMdave’s picture

I am just getting a white screen with this: (this is a combination of a couple of different samples.

$params = array(
    'metrics' => array('ga:visits'),
    'dimensions' => array('ga:browser'),
    'segment' => 'gaid::-2',
    'sort_metric' => array('-ga:visits'),
    'start_date' => strtotime('-31 days'),
    'end_date' => strtotime('-1 day'),
    'max_results' => 10,
  );

$feed = google_analytics_api_report_data($params);
dpm($feed);
print t('This page was viewed !count times', array('!count' => $visits)); 
grendzy’s picture

The first thing to always check after a white screen is your web server's error log. As a guess, perhaps you don't have the http://drupal.org/project/devel module enabled (it provides the dpm function).

When I ran your code, it produced this output:
https://skitch.com/dylan-tack/fmknw/screen-shot-2011-07-22-at-9.11.26-am

SWMdave’s picture

yep devel is off. i took a look at your screen shot. i didn't see the print output. did that come through also or did the dpm basically print first?

SWMdave’s picture

OK I can print the text, but can't seem to get the actual data from analytics to print. I don't need devel on all the time right? Just for dpm.

$params = array(
    'metrics' => array('ga:visits'),
    'dimensions' => array('ga:browser'),
    'segment' => 'gaid::-2',
    'sort_metric' => array('-ga:visits'),
    'start_date' => strtotime('-31 days'),
    'end_date' => strtotime('-1 day'),
    'max_results' => 10,
  );

$feed = google_analytics_api_report_data($params);
if ($feed) {
print t('This page was viewed !count times', array('!count' => $visits)); }
j_ten_man’s picture

I have created this for the 7.x version of the module. The patch does the following:

- Adds a new permission that you can give to your node authors.
- Adds a new tab on each node where the analytics report can be accessed by the author of the node with the corresponding permission or by the administrator.

This came out of some work I was doing for byronbay.com Pty Ltd.

If someone wants, it should be pretty straight forward to port back to D6.

SWMdave’s picture

That's awesome! I still can't get data to print. Only chart data seems to come through. Do you have an example for printing the data. If its not in a chart I just can't get the output.

j_ten_man’s picture

If the code you put in this thread is what you're actually trying to run, it definitely isn't going to print the number of visits. Where did you define $visits? You are trying to replace it in the output but never define it...
If you look at the output in #9, you will see that you'll need to do something like this:

$params = array(
    'metrics' => array('ga:visits'),
    'dimensions' => array('ga:browser'),
    'segment' => 'gaid::-2',
    'sort_metric' => array('-ga:visits'),
    'start_date' => strtotime('-31 days'),
    'end_date' => strtotime('-1 day'),
    'max_results' => 10,
  );

$feed = google_analytics_api_report_data($params);
if ($feed) {
  foreach ($feed->results as $browser_views) {
     print t('This page was viewed !count times in !browser.', array('!count' => $browser_views['visits'], '!browser' => $browser_views['browser'])); 
  }
  print t('This page was viewed !count times', array('!count' => $feed->totals['visits']));
}
SWMdave’s picture

I was getting ahead of myself. I threw a div in there. Here Is a quick example. Credit @ j_ten_man :

$params = array(
    'metrics' => array('ga:visits'),
    'dimensions' => array('ga:browser'),
    'segment' => 'gaid::-2',
    'sort_metric' => array('-ga:visits'),
    'start_date' => strtotime('-31 days'),
    'end_date' => strtotime('-1 day'),
    'max_results' => 10,
  );
$feed = google_analytics_api_report_data($params);
if ($feed) {
  foreach ($feed->results as $browser_views) {
     print t('<div><table><tr><td>!browser</td><td>!count</td></tr></table></div>',array('!count' => $browser_views['visits'], '!browser' => $browser_views['browser']));
  }
  print t ('This page was viewed !count times', array('!count' => $feed->totals['visits']));
}
SWMdave’s picture

Ok, getting back to an individual chart per user. I am going to try to have a drop down box and pass the form params to do this. Problem I am having now is the date range field.

Why can't I use : http://www.../url/URLparamStart=2011-08-01

$startDate = $_GET["URLparamStart"];
$params = array(
    'metrics' => array('ga:visits'),
    'dimensions' => array('ga:browser'),
    'segment' => 'gaid::-1',
    'sort_metric' => array('-ga:visits'),
    'start_date' =>  $startDate,
    'end_date' => strtotime('-1 day'),
    'max_results' => 150,
  );
$feed = google_analytics_api_report_data($params);
if ($feed) {
  foreach ($feed->results as $browser_views) {
     print t('<div><table><tr><td>!browser</td><td>!count</td></tr></table></div>',array('!count' => $browser_views['visits'], '!browser' => $browser_views['browser']));
  }
  print t ('This page was viewed !count times', array('!count' => $feed->totals['visits']));
}

I am happy to share my example when complete. we are almost there. I just need to get rid of that "strtotime('-1 day')," . I have been trying 'ga:date::2011-08-01' with no luck to do it first with out the param.

j_ten_man’s picture

See documentation on strtotime. It returns a unixtimestamp not a formatted date. You would need to do something like this:
$startDate = strtotime($_GET["URLparamStart"]);

SWMdave’s picture

YOu Rock. I was working going with : strtotime(date('2011-04-01')),

Your solution worked. Thanks. Here is working example code: I am passing: ?req=2011-04-01



$params = array(
    'metrics' => array('ga:visits'),
    'dimensions' => array('ga:browser'),
    'segment' => 'gaid::-1',
    'sort_metric' => array('-ga:visits'),
    'start_date' => strtotime($_GET["req"]),
    'end_date' => strtotime('-1 day'),
    'max_results' => 150,
  );
$feed = google_analytics_api_report_data($params);
if ($feed) {
  foreach ($feed->results as $browser_views) {
     print t('<div><table><tr><td>!browser</td><td>!count</td></tr></table></div>',array('!count' => $browser_views['visits'], '!browser' => $browser_views['browser']));
  }
  print t ('This page was viewed !count times', array('!count' => $feed->totals['visits']));
}
carvalhar’s picture

just a note: $feed->totals['visits'] means total visits at the entire site, not the page, your code isn't by page.

grendzy’s picture

Status: Postponed » Fixed

This isn't planned for the module, and it seems like the API questions were answered.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

aze2010’s picture

Issue summary: View changes

why not implement?!
This is a realy great function.

Thank for the patch!
Is it portable for D7?

plazik’s picture

@aze2010, for D7 you can use Google Analytics Views module to build your own custom dashboard and place it in tabs on node or user page. But I don't sure about contextual filters, they probably won't be work.
See also #2368151: Build reports in Reports module on Views.

aze2010’s picture

thanks for your reply!
I will have a look into it!

great module!!!

Update:

Sorry, but i dont get into it.
Which field, arguments etc do i have to configure to use such a function for a user-created content?

plazik’s picture

Version: 6.x-1.0-beta1 » 7.x-3.x-dev
Component: User interface » Views module
Assigned: raspberryman » Unassigned
Category: Support request » Feature request
Status: Closed (fixed) » Active

But I don't sure about contextual filters, they probably won't be work.

Added it to the feature request.

cthshabel’s picture

Component: Views module » All modules

We are building a dashboard that shows all the nodes created by site user/author.

This brings us to the point Plazik mentions in #25. This feature request would be great to allow users to be able to easily compare google analytics information against other nodes they have created. Being able to extract the necessary data and compare easily via a table would be extremely useful.

Creating a contextual filter for author would accomplish this I think. I would be happy to run tests if a patch is created. I am still practicing, but will give it a shot too (unfortunately, my php is messy :( ... but I can try)

Thanks!

plazik’s picture

Status: Active » Closed (fixed)

Further conversations about user relation will be in #1837230: Node, User, Organic Groups and others Entities relationships.