Google 広告リンク: insert

承認が必要です

ウェブ プロパティと Google 広告のリンクを作成します。 こちらから今すぐお試しいただけます。または、をご覧ください。

リクエスト

HTTP リクエスト

POST https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/entityAdWordsLinks

パラメータ

パラメータ名 説明
パスパラメータ
accountId string リンクを作成する Google アナリティクス アカウントの ID。
webPropertyId string リンクを作成するウェブ プロパティの ID。

承認

このリクエストは、次のスコープでの承認が必要です(認証と承認の詳細をご確認ください)。

スコープ
https://www.googleapis.com/auth/analytics.edit

リクエスト本文

リクエストの本文では、次のプロパティで Google 広告リンクリソースを指定します。

プロパティ名 説明 備考
必須プロパティ
adWordsAccounts[] list Google 広告クライアント アカウントのリスト。クライアント センターのアカウントは含まれません。Google 広告リンクを作成する場合、このフィールドは必須です。空にすることはできません。 書き込み可能
adWordsAccounts[].customerId string お客様 ID。Google 広告リンクを作成する場合、このフィールドは必須です。
name string リンクの名前。Google 広告リンクを作成する場合、このフィールドは必須です。 書き込み可能

レスポンス

正常終了した場合、このメソッドによって Google 広告リンクリソースを含むレスポンスの本文が返されます。

注: このメソッドで使用可能なコード例では、サポートされているプログラミング言語すべての例を示しているわけではありません(サポートされている言語の一覧については、クライアント ライブラリ ページをご覧ください)。

Java

Java クライアント ライブラリを使用します。

/*
 * Note: this code assumes you have an authorized Analytics service object.
 * See the Google Ads Links Developer Guide for details.
 */

/*
 * This request creates a new Google Ads Link.
 */

// Construct a list of AdWordsAccounts.
AdWordsAccount adWordsAccount = new AdWordsAccount();
adWordsAccount.setCustomerId("123-456-7890");
List<AdWordsAccount> adWordsAccounts = Arrays.asList(adWordsAccount);

// Construct the body of the request.
EntityAdWordsLink adWordsLink = new EntityAdWordsLink();
adWordsLink.setAdWordsAccounts(adWordsAccounts);
adWordsLink.setName("Google Ads Link");

try{
  analytics.management().webPropertyAdWordsLinks().insert("123456",
      "UA-123456-1", adWordsLink).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

PHP

PHP クライアント ライブラリを使用します。

/**
 * Note: This code assumes you have an authorized Analytics service object.
 * See the Google Ads Links Developer Guide for details.
 */

/**
 * This request creates a new Google Ads Link.
 */

// Construct an Google Ads account object.
$adWordsAccount = new Google_Service_Analytics_AdWordsAccount();
$adWordsAccount->setCustomerId("123-456-7890");

// Construct the body of the request.
$adWordsLink = new Google_Service_Analytics_EntityAdWordsLink();
$adWordsLink->setName('Google Ads Link');
$adWordsLink->setAdWordsAccounts(array($adWordsAccount));

try {
  $analytics->management_webPropertyAdWordsLinks->insert('123456',
      'UA-123456-1', $adWordsLink);

} catch (apiServiceException $e) {
  print 'There was an Analytics API service error '
      . $e->getCode() . ':' . $e->getMessage();

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

Python

Python クライアント ライブラリを使用します。

# Note: This code assumes you have an authorized Analytics service object.
# See the Google Ads Links Developer Guide for details.

# This request creates a new Google Ads Link.
try:
  analytics.management().webPropertyAdWordsLinks().insert(
      accountId='123456',
      webPropertyId='UA-123456-1',
      body={
          'adWordsAccounts': [
              {
                  'customerId': '123-456-7890'
              }
          ],
          'name': 'Google Ads Link'
      }
  ).execute()

except TypeError, error:
  # Handle errors in constructing a query.
  print 'There was an error in constructing your query : %s' % error

except HttpError, error:
  # Handle API errors.
  print ('There was an API error : %s : %s' %
         (error.resp.status, error.resp.reason))

JavaScript

JavaScript クライアント ライブラリを使用します。

/*
 * Note: This code assumes you have an authorized Analytics client object.
 * See the Google Ads Links Developer Guide for details.
 */

/*
 * This request creates a new Google Ads Link.
 */
function insertAdWordsLink() {
  var request = gapi.client.analytics.management.webPropertyAdWordsLinks.insert(
    {
      'accountId': '123456',
      'webPropertyId': 'UA-123456-1',
      'resource': {
        'adWordsAccounts': [ { 'customerId': '123-456-7890'} ],
        'name': 'Google Ads Link'
      }
    });
  request.execute(function (response) { // Handle the response. });
}

試してみる

以下の API Explorer を使用し、ライブデータに対してこのメソッドを呼び出して、レスポンスを確認してみましょう。 または、スタンドアロンのテストツールをご利用ください。