AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Optimize
2.8K members online now
2.8K members online now
Get answers to frequently asked questions, read the glossary of testing terminology and explore some example experiment ideas to get the creative juices flowing.
Guide Me
star_border
Reply

Google Optimize API

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Currently we use a dashboard to view progress of all Google Analytics Experiments on our TV dashboard. It's awesome. Here's the code in PHP:

 

function googleGetExperiments()
{
    $scopes = [ 'https://www.googleapis.com/auth/analytics.readonly' ];
    $client = new Google_Client();
    $client->setAuthConfig(CREDENTIALS_FILE);
    $client->setScopes($scopes);

    $service = new Google_Service_Analytics($client);
    $experimentData = array();
    $profiles = $service->management_profiles->listManagementProfiles("~all", "~all");
    foreach ($profiles['items'] as $profile) {
      $experiments = $service->management_experiments->listManagementExperiments($profile['accountId'], $profile['webPropertyId'], $profile['id']);
      if (isset($experiments['items']))
        foreach ($experiments['items'] as $experiment) {
          //    if ($experiment['status'] != 'RUNNING') continue;
          $retval[] = $experiment;
        }
    }
    return $retval;
}

$experimentData = googleGetExperiments();
$progressClasses = array('progress-bar progress-bar-success','progress-bar progress-bar-info','progress-bar progress-bar-warning', 'progress-bar progress-bar-danger','progress-bar progress-bar-success','progress-bar progress-bar-info','progress-bar progress-bar-warning', 'progress-bar progress-bar-danger');

foreach ($experimentData as $experiment) {
  echo "<tr>";
  if ($experiment['status'] == 'RUNNING')
    echo '<td><a class="btn btn-xs btn-success"><i class="glyphicon glyphicon-ok"></i></a>';
  else
    echo '<td><a class="btn btn-xs btn-danger"><i class="glyphicon glyphicon-remove"></i></a>';
  $expHref = "https://www.google.com/analytics/web/?pli=1#siteopt-experiment/siteopt-detail/a{$experiment['accountId']}w{$experiment['internalWebPropertyId']}p{$experiment['profileId']}/%3F_r.drilldown%3Danalytics.gwoExperimentId%3A{$experiment['id']}/";
  echo " <a href='$expHref' target='_blank'>{$experiment['name']}</a>";
  echo "<td>{$experiment['variations'][0]['url']}";
  echo "<td>".date('Y-m-d',strtotime($experiment['startTime']));
  echo "<td>";

  echo '<div class="progress" style="width:200px">';
  foreach ($experiment['variations'] as $i => $variation) {
    echo '<a href="'.$variation['url'].'" target="_blank"><div class="'.$progressClasses[$i].'" role="progressbar" style="width: '.(100*$variation['weight']).'%" title="'.$variation['name'].'"></div></a>';
  }
  echo '</div>';
}

Because there is this big deprecation notice for experiments, I am considering to switch to Optimize. But naturally, I want my experience to be better not worse.

 

Is there any API available or workaround to get this data? I would like to make a similar dashboard with Optimize.

1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author William E
November

Google Optimize API

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭

Hey William.

 

I know this may be a little late, but the answer is yes. All the fields you are accessing in your code above are available. The API Docs are available here: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/experiment...

 

The only thing I have found, is that you can't access all the data that the Optimize UI has. For one, I would love to pull screenshots, but it doesn't appear thats available via the API and the variation URL field is always blank for me. The second item I am trying to access is the metric data that is displayed when viewing an experiment (conversion/page views number/ sessions/etc)

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author William E
November

Google Optimize API

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭

Hey William.

 

I know this may be a little late, but the answer is yes. All the fields you are accessing in your code above are available. The API Docs are available here: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/experiment...

 

The only thing I have found, is that you can't access all the data that the Optimize UI has. For one, I would love to pull screenshots, but it doesn't appear thats available via the API and the variation URL field is always blank for me. The second item I am trying to access is the metric data that is displayed when viewing an experiment (conversion/page views number/ sessions/etc)

Google Optimize API

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

nevermind.. i just figured out how to get the metric data using the core_reporting_api: https://developers.google.com/analytics/devguides/reporting/core/v3/reference#ids

 

You can filter based on ga:experimentId and use ga:experimentVariant as your dimension to show variant specific data.

Google Optimize API

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

Cool, thanks for your help.

Google Optimize API

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Hi there,

 

Does someone know how to get the results of an experiment? It's about metrics
- Improvement
- Probability to be Best
- Probability to beat baseline

Google Optimize API

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

Hi Mark! I was wondering if you ever found a way to retrieve the variation data properly as I'm also getting blank URLs on some experiment's variations and I'm trying to manage the experiment server side on Nodejs.
Thank you!

Google Optimize API

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

@Facundo C unfortunately the api does not provide the urls and I'm not sure when they plan to build that functionality into it.

 

In regards to variation data, the metrics i am pulling are: 

'ga:users','ga:sessions','gaSmiley Tongueageviews', 'ga:sessionDuration', 'ga:avgSessionDuration', 'ga:bounces', 'ga:bounceRate'

 

Hope this helps. The API really only pulls in any Optimize data that is available in GA.

You can find the complete list of metrics here: https://developers.google.com/analytics/devguides/reporting/core/dimsmets

Google Optimize API

[ Edited ]
Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭

Sorry @Юрий Д I somehow missed this but just take a look at my response below... the metrics you have available to you are documented here: https://developers.google.com/analytics/devguides/reporting/core/dimsmets

 

I am currently pulling: 

'ga:users','ga:sessions','gaSmiley Tongueageviews', 'ga:sessionDuration', 'ga:avgSessionDuration', 'ga:bounces', 'ga:bounceRate'

Google Optimize API

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭

Thank you @_markanthonydj I must say I'm confused, why would you expose this if you won't put out all the relevant info? How am I supposed to manage my experiments server side if I can't match the URLs?? now I'm stuck with the client side implementation, it's useless really this experiments list Smiley Sad

Google Optimize API

Visitor ✭ ✭ ✭
# 10
Visitor ✭ ✭ ✭

@Facundo C totally agree... however.. here's a little hack i came up with that i add to reference my google experiments from our own app. It links you to the google analytics view of the experiment... and from there you can go into google optimize... i know this is sub-optimal, but its all there is (that i know of)

https://analytics.google.com/analytics/web/#siteopt-experiment/siteopt-detail/a{account_id}w{internal_web_property_id}p{profile_id}/%3F_r.drilldown%3Danalytics.gwoExperimentId%3A{experiment_id}/