2K members online now
2K 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
Highlighted

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.

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

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