Exemple #1
0
The --sampling-level argument provides a way to express a preference regarding the degree of
sampling in the Google Analytics data. If the option "none" is used, the report will be treated
as having failed if Google reports sampling as being present in the results; in this case the user
must specify a shorter time interval in the --split-queries-by option in order to avoid data
sampling.

The --formatter argument may be used to specify the name of a PHP class that inherits from
Google\\Analytics\\ReportFormatter; an instance of this class will be used to format the report's
contents.

The --name argument only makes sense when emailing a report; it allows for the specification of a
meaningful name to describe the report's contents.

The --group-name argument fulfills a similar function to the --name argument, but applies when
including multiple reports in the same file, and will be used to describe the entire collection.
This argument is ignored if specified when running only a single report.

EOF
);
require_once __DIR__ . DIRECTORY_SEPARATOR . 'bootstrap.php';
try {
    try {
        $args = PFXUtils::collapseArgs(array(), array('profile-name:', 'profile-id:', 'metric:', 'start-date:', 'end-date:', 'email:', 'file:', 'dimension:', 'sort:', 'limit:', 'filter:', 'segment:', 'split-queries-by:', 'date-format-string:', 'sampling-level:', 'name:', 'group-name:', 'formatter:', 'conf:', 'help'));
        $ga = new Google\Analytics\API();
        Google\Analytics\QueryConfiguration::createFromCommandLineArgs($args)->run($ga);
    } catch (InvalidArgumentException $e) {
        PFXUtils::printUsage($e->getMessage(), 1, true);
    }
} catch (Exception $e) {
    echo PFXUtils::buildExceptionTrace($e) . "\n";
}
#!/usr/bin/env php
<?php 
define('PFX_USAGE_MESSAGE', <<<EOF
Usage: {FILE} [-f|--force-refresh]
{PAD} [-h|--help]

This script prints a structured list of the Google Analytics properties to which the effective
credentials permit access. If the --force-refresh argument is used, the script will always make a
new query to the Google Analytics API rather than using information from the database.

EOF
);
require_once __DIR__ . DIRECTORY_SEPARATOR . 'bootstrap.php';
try {
    $args = PFXUtils::collapseArgs(array('f', 'h'), array('force-refresh', 'help'));
    $ga = new Google\Analytics\API();
    if ($args['force-refresh']) {
        $ga->clearAccountCache();
    }
    $accounts = $ga->getAccountSummaries();
    sortByName($accounts);
    foreach ($accounts as $account) {
        printf("(account:%s) %s:\n", $account->getID(), $account->getName());
        $webProperties = $account->getWebPropertySummaries();
        sortByName($webProperties);
        foreach ($webProperties as $webProperty) {
            printf("\t(web property:%s) (%s) %s:\n", $webProperty->getID(), $webProperty->getName(), $webProperty->getURL());
            $profiles = $webProperty->getProfileSummaries();
            sortByName($profiles);
            foreach ($profiles as $profile) {
                printf("\t\t(profile:%s) %s\n", $profile->getID(), $profile->getName());