NAME

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

VERSION

version 0.11002

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->ids('ga:1234567'); # your Analytics profile ID
$req->dimensions('ga:country');
$req->metrics('ga:visits');
$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;

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.

CONSTRUCTOR

new

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

The constructor doesn't take any arguments.

ATTRIBUTES

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

This software is copyright (c) 2010 by Nick Wellnhofer.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.