NAME

Mojo::GoogleAnalytics::Report - Represents a Google Analytics report

SYNOPSIS

See Mojo::GoogleAnalytics.

DESCRIPTION

Mojo::GoogleAnalytics::Report represents a result from "batch_get" in Mojo::GoogleAnalytics.

ATTRIBUTES

count

$int = $self->count;

Returns the total count of rows that can be returned by Google Analytics.

error

$hash_ref = $self->error;

Holds a hash ref if an error occurred and undef if not. Example data structure:

{
  code    => 403,
  message => "Something went wrong",
}

maximums

$hash_ref = $self->maximums;

Holds a hash ref with the maximum metrics. Example:

{
  "ga:pageviews" => 349,
  "ga:sessions"  => 40,
}

minimums

$hash_ref = $self->minimums;

See "maximums".

page_token

$str = $self->page_token;

Holds a token that can be used to query Google Analytics for more data.

query

$hash_ref = $self->query;

Holds the query passed on to "batch_get" in Mojo::GoogleAnalytics.

rows

$array_ref = $self->rows;

Holds the row data returned from Google Analytics. Example:

[
  {
    dimensions => ["Norway", "Chrome"],
    metrics    => [{values => [349, 40]}],
  },
  ...
]

totals

$hash_ref = $self->totals;

See "maximums".

tx

$tx = $self->tx;

Holds the raw Mojo::Transaction object used in the request. Useful if you need to extract raw data:

my $raw_data = $tx->res->json;

METHODS

rows_to_hash

$hash_ref = $self->rows_to_hash;

Creates a multi dimensional hash, from the "dimensions" in the rows. Example result:

# Query dimensions: [{name => 'ga:country'}, {name => 'ga:browser'}]
# Result:
{
  Norway => {
    Chrome => {
      "ga:pageviews" => 349,
      "ga:sessions"  => 40,
    },
    ...
  },
  ...
}

rows_to_table

$array_ref = $self->rows_to_table(no_headers => 1);
$str = $self->rows_to_table(as => "text", no_headers => 1);

Converts "rows" into tabular data. as can be used to return the table as either "text" or "hash" (default). Set no_headers to a true value to avoid getting the first item in the $array_ref as header names. Example "text" output:

ga:country  ga:browser  ga:pageviews  ga:sessions
Sweden      Chrome      472493        43340
Sweden      Safari      413833        43242
Denmark     Safari      127321        13975
Denmark     Chrome      124904        12077
Norway      Chrome      105998        10066

AUTHOR

Jan Henning Thorsen

COPYRIGHT AND LICENSE

Mojo::GoogleAnalytics.

SEE ALSO

Mojo::GoogleAnalytics.