NAME

Net::Google::Analytics - Simple interface to the Google Analytics Data Export API

DESCRIPTION

This module provides a simple, straight-forward interface to the Google Analytics Data Export API, using LWP::UserAgent and XML::LibXML for the heavy lifting.

See http://code.google.com/apis/analytics/docs/gdata/gdataDeveloperGuide.html for the complete API documentation.

SYNOPSIS

use Net::Google::Analytics;
use Net::Google::AuthSub;

my $auth = Net::Google::AuthSub->new(service => 'analytics');
$auth->login($user, $pass);

my $analytics = Net::Google::Analytics->new();
$analytics->auth_params($auth->auth_params);

my $data_feed = $analytics->data_feed;
my $req = $data_feed->new_request();
$req->dimensions('ga:...');
$req->metrics('ga:...');
$req->start_date('YYYY-MM-DD');
$req->end_date('YYYY-MM-DD');
my $res = $data_feed->retrieve($req);

my $entry = $res->entries->[$i];
print $entry->dimensions->[0]->value;
print $entry->metrics->[0]->value;

CONSTRUCTOR

new

my $analytics = Net::Google::Analytics->new();

The constructor doesn't take any arguments.

ACCESSORS

account_feed

The Analytics account feed, an object of type Net::Google::Analytics::AccountFeed.

data_feed

The Analytics data feed, an object of type Net::Google::Analytics::DataFeed.

terminal

Object that implements the following callback methods for interactive authentication:

$terminal->auth_params

my @auth_params = $terminal->auth_params();

This method is called before a feed request and the result is stored in auth_params if auth_params has not been sent. It may return cached auth params.

$terminal->new_auth_params

my @auth_params = $terminal->new_auth_params($service, error => $error);

This method is called if a HTTP request for a feed returns a 401 status code. Then auth_params is reset and the HTTP request is retried.

METHODS

auth_params

$analytics->auth_params(@auth_params);

Set the authentication parameters as key/value pairs. The values returned from "auth_params" in Net::Google::AuthSub can be used directly.

user_agent

$analytics->user_agent($ua);

Sets the LWP::UserAgent object to use for HTTP(S) requests. You only have to call this method if you want to provide your own user agent, e.g. to change the HTTP user agent header.

AUTHOR

Nick Wellnhofer <wellnhofer@aevum.de>

COPYRIGHT AND LICENSE

Copyright (C) Nick Wellnhofer, 2010

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.0 or, at your option, any later version of Perl 5 you may have available.