Custom Dimensions: insert

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

สร้างมิติข้อมูลที่กำหนดเองใหม่ ลองใช้เลยหรือดูตัวอย่าง

ส่งคำขอ

คำขอ HTTP

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

พารามิเตอร์

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

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

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

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

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

ในเนื้อหาคำขอ ให้ระบุทรัพยากรmanagement.customDimension

คำตอบ

หากทำสำเร็จ เมธอดนี้จะแสดงผลทรัพยากรmanagement.customDimension ในเนื้อหาการตอบกลับ

ตัวอย่าง

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

Java

ใช้ไลบรารีของไคลเอ็นต์ Java

/*
 * Note: This code assumes you have an authorized Analytics service object.
 */

/*
 * This request creates a new custom dimension.
 */

// Construct the body of the request and set its properties.
CustomDimension body = new CustomDimension();
body.setName("Campaign Group");
body.setScope("SESSION");
body.setActive(true);

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

Python

ใช้ไลบรารีของไคลเอ็นต์ Python

# Note: This code assumes you have an authorized Analytics service object.

# This request creates a new custom dimension.
try:
  analytics.management().customDimensions().insert(
      accountId='123456',
      webPropertyId='UA-123456-1',
      body={
          'name': 'Campaign Group',
          'scope': 'SESSION',
          'active': True
      }
  ).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))

ลองใช้เลย

ใช้ API Explorer ด้านล่างเพื่อเรียกใช้เมธอดนี้ในข้อมูลสดและดูการตอบสนอง หรือลองใช้เครื่องมือสำรวจแบบสแตนด์อโลน