Fine-tuning a search with Analytics API + PHP

Asked

Viewed 45 times

1

Could someone help me mount a search? in the google API?

1) The original and that works, and returns me how many sessions were made in that period, is the same as in the google example:

function getResultsA(&$analytics, $profileId) {<br>
  // Calls the Core Reporting API and queries for the number of sessions<br>
  // for the last seven days.<br>
   return $analytics->data_ga->get(<br>
       'ga:' . $profileId,<br>
       '7daysAgo',<br>
       'today',<br>
       'ga:sessions');<br>
}

2) I need to pick up the "KEY WORDS" (ga:keyword) as in the example that works by analyitics panel...

as in this example

that is, in this example I have a "Metric" + "Dimension" that work!! and bring me all the Keywords!!

3) SOON THE QUESTION, what would the same search look like in gapi + php? like this?

function getResultsA(&$analytics, $profileId) {<br>
  // Calls the Core Reporting API and queries for the number of sessions<br>
  // for the last seven days.<br>
   return $analytics->data_ga->get(<br>
       'ga:' . $profileId,<br>
       '7daysAgo',<br>
       'today',<br>
       //'ga:sessions');<br>
       'ga:sessions, ga:keyword, -ga:sessions');<br>
}

Being that I’m only getting error message saying that the "metric is unknown"

I made several unsuccessful combinations and did not find an example of how to "write" this search.

2 answers

0

function getResultsA(&$analytics, $profileId) {

        $metricas = 'ga:sessions,ga:transactions,ga:transactionsPerSession,ga:transactionRevenue';
        $dimensions = 'ga:campaign,ga:source,ga:adContent,ga:medium,ga:keyword';

        return $analytics->data_ga->get(
            'ga:' . $profileId,
            '7daysAgo',
            'today',
            $metricas,
            array('dimensions' => $dimensions)
        );
    }
  • Could you add an explanation to your answer? It is always good to have an explanation about the modifications so that everyone can better understand what is being done

0

The message "Unknown metric" is displayed because ga:keyword is a dimension, not a metric. Try the query as follows:

$analytics->data_ga->get(
            'ga:xxxxxx',
            '7daysAgo',
            'today',
            ['ga:sessions'],
            ['ga:keyword']
);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.