Narrowing a search with Analytics API + PHP

1

Could anyone help me set up a search? in the google API?

1) The original and that works, and returns me how many sessions were done in that period, is the same as 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 get the "KEY WORDS" (ga: keyword) as in the example that works through the analytics panel ...

as in this example

That is, in this example I have a "metric" + "dimension" that works !! and bring me all the keywords !!

3) LOGO THE QUESTION, how would the same search in gapi + php look? so?

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 an error message saying that "metric is unknown"

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

    
asked by anonymous 01.09.2015 / 08:30

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)
        );
    }
    
22.08.2016 / 21:26
0

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

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