3

Google APIのこのコードを使用しています

すべての目標の名前と番号を取得しています

しかし、目標達成額を得る方法がわかりません

これは私が得るものです:

            Account ID               = xxx
            Web Property ID          = xxx
            Internal Web Property ID = xxx
            Profile ID               = xxx


            Goal Number = 1
            Goal Name   = Open User (MT Register)
            Goal Value  = 0
            Goal Active = 1
            Goal Type   = URL_DESTINATION

            Created = 2012-07-22T10:20:02.183Z
            Updated = 2012-08-15T12:43:06.045Z



Goal URL            = /04_thankyou.php
Case Sensitive      = 
Match Type          = REGEX
First Step Required = 1

Destination Goal Steps


Step Number = 1
Step Name   = abc
  Step URL    = /01_insert_phone.php



Step Number = 2
Step Name   = abcd
  Step URL    = /02_progress.step



Step Number = 3
Step Name   = abcde
  Step URL    = /03_insert_pincode.php

これはコードです:

function getEventDetailsHtml(&$details) {
  $html = '<h4>Event Goal</h4><pre>' .
          'Use Event Value = ' . $details->getUseEventValue();

  // Get all the event goal conditions.
  $conditions = $details->getEventConditions();

  foreach ($conditions as &$condition) {
    $html .= "Event Type = $condition->getEventType()";

    $eventType = $condition->getType();
    if ($condition->getType() == 'VALUE') {
      // Process VALUE.
      $html .= "Comparison Type  = $condition->getComparisonType()" .
               "Comparison Value = $condition->getComparisonValue()";

    } else {
      // Process CATEGORY, ACTION, LABEL.
      $html .= "Match Type = $condition->getMatchType()" .
               "Expression = $condition->getExpression()";
    }
  }

  return $html . '</pre>';
}

function getVisitNumPagesDetailsHtml(&$details) {
  $html = '<h4>Visit Num Pages Goal</h4>';
  $html .= <<<HTML
<pre>

Comparison Type  = {$details->getComparisonType()}
Comparison Value = {$details->getComparisonValue()}

</pre>
HTML;
  return $html;
}

function getVisitTimeOnSiteDetailsHtml(&$details) {
  $html = '<h4>Visit Time On Site Goal</h4>';
  $html .= <<<HTML
<pre>

Comparison Type  = {$details->getComparisonType()}
Comparison Value = {$details->getComparisonValue()}

</pre>
HTML;
  return $html;
}

function getUrlDestinationDetailsHtml(&$details) {
  $html .= <<<HTML

<pre>

Goal URL            = {$details->getUrl()}
Case Sensitive      = {$details->getCaseSensitive()}
Match Type          = {$details->getMatchType()}
First Step Required = {$details->getFirstStepRequired()}

</pre>
HTML;

  $html .= '<h4>Destination Goal Steps</h4>';
  $steps = $details->getSteps();
  if (count($steps) == 0) {
    $html .= '<p>No Steps Configured</p>';

  } else {
    foreach ($steps as &$step) {
      $html .= <<<HTML
<pre>

Step Number = {$step->getNumber()}
Step Name   = {$step->getName()}
  Step URL    = {$step->getUrl()}

  </pre>
HTML;
    }
  }
  return $html;
}

    require_once 'google_api.php';

    if (isset($_SESSION['token'])) { 
        $client->setAccessToken($_SESSION['token']); 
    }

    if (!$client->getAccessToken()) {
      $authUrl = $client->createAuthUrl();
      print "<a class='login' href='$authUrl'>Connect Me!</a>";

    } else {
      $analytics = new Google_AnalyticsService($client);

        try {
          $goals = $analytics->management_goals
                             ->listManagementGoals('25788360',
                                                   'UA-25788360-20',
                                                   '~all');

        } catch (Exception $e) {
          print 'There was a general API error '
            . $e->getCode() . ':' . $e->getMessage();
        }

        $html = '';
$items = $goals->getItems();
  foreach ($items as &$goal) {
    $html .= "
            <pre>
            Account ID               = {$goal->getAccountId()}
            Web Property ID          = {$goal->getWebPropertyId()}
            Internal Web Property ID = {$goal->getInternalWebPropertyId()}
            Profile ID               = {$goal->getProfileId()}


            Goal Number = {$goal->getId()}
            Goal Name   = {$goal->getName()}
            Goal Value  = {$goal->getValue()}
            Goal Active = {$goal->getActive()}
            Goal Type   = {$goal->getType()}

            Created = {$goal->getCreated()}
            Updated = {$goal->getUpdated()}
            </pre>";

    // Now get the HTML for the type of goal.
    switch($goal->getType()) {
      case 'URL_DESTINATION':
        $html .= getUrlDestinationDetailsHtml(
            $goal->getUrlDestinationDetails());
        break;

      case 'VISIT_TIME_ON_SITE':
        $html .= getVisitTimeOnSiteDetailsHtml(
            $goal->getVisitTimeOnSiteDetails());
        break;

      case 'VISIT_NUM_PAGES':
        $html .= getVisitNumPagesDetailsHtml(
            $goal->getVisitNumPagesDetails());
        break;

      case 'EVENT':
        $html .= getEventDetailsHtml(
            $goal->getEventDetails());
        break;
  }

    echo $html;
}
4

1 に答える 1

1

管理APIを使用しているようです。これは、管理のみを目的としています。目標の取得と設定。

目標からのデータも必要な場合は、CoreReportingAPIを確認する必要があります。

目標に利用できるデータはここにあります: https ://developers.google.com/analytics/devguides/reporting/core/dimsmets/goalconversions

実装ガイドはここにあります: https ://developers.google.com/analytics/devguides/reporting/core/v3/coreDevguide

Google APIの使用を設定する方法をすでに知っているので、完全な実装例は提供しませんでした。

あなたの探求で頑張ってください!

編集:それを使用する方法の例を追加しました:

<?php
$client = new apiAnalyticsService();

function queryCoreReportingApi() {
    $optParams = array( //OPTINAL SETTINGS
      'dimensions' => '', //A comma-separated list of Multi-Channel Funnels dimensions. E.g., 'mcf:source,mcf:medium'. (string)
      'sort' => '', //A comma-separated list of dimensions or metrics that determine the sort order for the Analytics data. (string)
      'filters' => '', //A comma-separated list of dimension or metric filters to be applied to the Analytics data. (string)
      'start-index' => '', //An index of the first entity to retrieve. Use this parameter as a pagination mechanism along with the max-results parameter. (integer, 1+)
      'fields' => '', //Selector specifying which fields to include in a partial response.
      'max-results' => '25'); //The maximum number of entries to include in this feed. (integer)

  return $service->data_mcf->get(
      $id, //Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics profile ID. (string)
      '2010-01-01', //Start date for fetching Analytics data. All requests should specify a start date formatted as YYYY-MM-DD. (string)
      '2010-01-15', //End date for fetching Analytics data. All requests should specify an end date formatted as YYYY-MM-DD. (string)
      'ga:totalConversions', //A comma-separated list of Multi-Channel Funnels metrics. E.g., 'mcf:totalConversions,mcf:totalConversionValue'. At least one metric must be specified. (string)
      $optParams);
}
于 2013-02-03T12:35:56.500 に答える