Google Ads Links: insert

ต้องมีการให้สิทธิ์

สร้างลิงก์ webProperty-Google Ads ลองใช้เลยหรือดูตัวอย่าง

ส่งคำขอ

คำขอ HTTP

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

พารามิเตอร์

ชื่อพารามิเตอร์ ค่า คำอธิบาย
พารามิเตอร์เส้นทาง
accountId string รหัสของบัญชี Google Analytics ที่จะสร้างลิงก์
webPropertyId string รหัสเว็บพร็อพเพอร์ตี้ที่จะสร้างลิงก์

การให้สิทธิ์

คำขอนี้ต้องได้รับการให้สิทธิ์ตามขอบเขตต่อไปนี้ (อ่านเพิ่มเติมเกี่ยวกับการตรวจสอบสิทธิ์และการให้สิทธิ์)

ขอบเขต
https://www.googleapis.com/auth/analytics.edit

เนื้อหาของคำขอ

ในเนื้อหาคำขอ ให้ระบุแหล่งข้อมูลลิงก์ Google Ads พร้อมด้วยพร็อพเพอร์ตี้ต่อไปนี้

ชื่อพร็อพเพอร์ตี้ ค่า คำอธิบาย Notes
พร็อพเพอร์ตี้ที่จำเป็น
adWordsAccounts[] list รายการบัญชีลูกค้า Google Ads บัญชีเหล่านี้ต้องไม่เป็นบัญชี MCC ต้องระบุข้อมูลในช่องนี้เมื่อสร้างลิงก์ Google Ads ต้องระบุ เขียนได้
adWordsAccounts[].customerId string รหัสลูกค้า ต้องระบุข้อมูลในช่องนี้เมื่อสร้างลิงก์ Google Ads
name string ชื่อของลิงก์ ต้องระบุข้อมูลในช่องนี้เมื่อสร้างลิงก์ Google Ads เขียนได้

คำตอบ

หากสำเร็จ เมธอดนี้จะแสดงแหล่งข้อมูลลิงก์ Google Ads ในเนื้อหาการตอบสนอง

ตัวอย่าง

หมายเหตุ: ตัวอย่างโค้ดที่มีสำหรับวิธีการนี้ไม่ได้แสดงถึงภาษาโปรแกรมที่รองรับทั้งหมด (ดูรายการภาษาที่รองรับได้ในหน้าไลบรารีของไคลเอ็นต์)

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 ด้านล่างเพื่อเรียกใช้เมธอดนี้ในข้อมูลสดและดูการตอบสนอง หรือลองใช้เครื่องมือสำรวจแบบสแตนด์อโลน