ต้องมีการให้สิทธิ์
สร้างการทดสอบใหม่ ดูตัวอย่าง
นอกเหนือจากพารามิเตอร์มาตรฐาน เมธอดนี้ยังรองรับพารามิเตอร์ที่แสดงในตารางพารามิเตอร์ด้วย
ส่งคำขอ
คำขอ HTTP
POST https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/profiles/profileId/experiments
พารามิเตอร์
ชื่อพารามิเตอร์ | ค่า | คำอธิบาย |
---|---|---|
พารามิเตอร์เส้นทาง | ||
accountId |
string |
รหัสบัญชีที่จะสร้างการทดสอบ |
profileId |
string |
รหัสข้อมูลพร็อพเพอร์ตี้ (โปรไฟล์) เพื่อสร้างการทดสอบ |
webPropertyId |
string |
รหัสเว็บพร็อพเพอร์ตี้ที่จะสร้างการทดสอบ |
การให้สิทธิ์
คำขอนี้ต้องได้รับการให้สิทธิ์อย่างน้อย 1 ขอบเขตต่อไปนี้ (อ่านเพิ่มเติมเกี่ยวกับการตรวจสอบสิทธิ์และการให้สิทธิ์)
ขอบเขต |
---|
https://www.googleapis.com/auth/analytics |
https://www.googleapis.com/auth/analytics.edit |
เนื้อหาของคำขอ
ในเนื้อหาคำขอ ให้ระบุทรัพยากรmanagement.experiment พร้อมกับพร็อพเพอร์ตี้ต่อไปนี้
ชื่อพร็อพเพอร์ตี้ | ค่า | คำอธิบาย | Notes |
---|---|---|---|
พร็อพเพอร์ตี้ที่จำเป็น | |||
name |
string |
ชื่อการทดสอบ ไม่สามารถเปลี่ยนแปลงฟิลด์นี้ได้สำหรับการทดสอบที่มีสถานะ "ENDED" ต้องระบุข้อมูลในช่องนี้เมื่อสร้างการทดสอบ | เขียนได้ |
status |
string |
สถานะการทดสอบ ค่าที่เป็นไปได้ ได้แก่ "DRAFT", "READY_TO_RUN", "RUNning", "ENDED" คุณสามารถสร้างการทดสอบได้ในสถานะ "DRAFT", "READY_TO_RUN" หรือ "RUNning" ต้องระบุข้อมูลในช่องนี้เมื่อสร้างการทดสอบ | เขียนได้ |
variations[].name |
string |
ชื่อของรูปแบบ ต้องระบุข้อมูลในช่องนี้เมื่อสร้างการทดสอบ ไม่สามารถเปลี่ยนแปลงฟิลด์นี้ได้สำหรับการทดสอบที่มีสถานะ "ENDED" | เขียนได้ |
พร็อพเพอร์ตี้ที่ไม่บังคับ | |||
description |
string |
หมายเหตุเกี่ยวกับการทดสอบนี้ | เขียนได้ |
editableInGaUi |
boolean |
หากเป็นจริง ผู้ใช้ปลายทางจะแก้ไขการทดสอบผ่านอินเทอร์เฟซผู้ใช้ Google Analytics ได้ | เขียนได้ |
equalWeighting |
boolean |
บูลีนที่ระบุว่าจะกระจายการเข้าชมในทุกรูปแบบอย่างเท่าเทียมกันหรือไม่ หากค่าเป็น "เท็จ" การทดสอบเนื้อหาจะใช้พฤติกรรมเริ่มต้นของการปรับการเข้าชมแบบไดนามิกตามประสิทธิภาพของรูปแบบต่างๆ ไม่บังคับ -- ค่าเริ่มต้นคือ "เท็จ" ไม่สามารถเปลี่ยนแปลงฟิลด์นี้ได้สำหรับการทดสอบที่มีสถานะ "ENDED" | เขียนได้ |
minimumExperimentLengthInDays |
integer |
จำนวนเต็มใน [3, 90] ระบุระยะเวลาขั้นต่ำของการทดสอบ เปลี่ยนแปลงสำหรับการทดสอบที่ดำเนินอยู่ได้ ไม่สามารถเปลี่ยนแปลงฟิลด์นี้ได้สำหรับการทดสอบที่มีสถานะ "ENDED" | เขียนได้ |
objectiveMetric |
string |
เมตริกที่การทดสอบเพิ่มประสิทธิภาพ ค่าที่ถูกต้อง: "ga:goal(n)Completions", "ga:adsenseAdsclicks", "ga:adsenseAdsViewed", "ga:adsenseRevenue", "ga:bounces", "ga:pageviews", "ga:sessionDuration", "ga:transactions", "ga:transactionRevenue" ต้องระบุข้อมูลในช่องนี้หากสถานะเป็น "RUNING" และกรอบการแสดงผลเป็น "REDIRECT" หรือ "API" | เขียนได้ |
optimizationType |
string |
ควรย่อหรือขยายวัตถุประสงค์เมตริกให้สูงสุดหรือไม่ ค่าที่เป็นไปได้: "MAXIMUM", "MINIMUM" ไม่บังคับ -- ค่าเริ่มต้นคือ "MAXIMUM" ระบุไม่ได้หากไม่มีobjectMetric แก้ไขไม่ได้เมื่อสถานะเป็น "กำลังทำงาน" หรือ "สิ้นสุด" | เขียนได้ |
rewriteVariationUrlsAsOriginal |
boolean |
บูลีนที่ระบุว่ามีการเขียน URL รูปแบบใหม่เพื่อให้ตรงกับ URL ต้นฉบับหรือไม่ ไม่สามารถเปลี่ยนแปลงฟิลด์นี้ได้สำหรับการทดสอบที่มีสถานะ "ENDED" | เขียนได้ |
servingFramework |
string |
เฟรมเวิร์กที่ใช้แสดงรูปแบบต่างๆ ของการทดสอบและประเมินผลลัพธ์ ข้อใดข้อหนึ่ง:
|
เขียนได้ |
trafficCoverage |
double |
จำนวนทศนิยมระหว่าง 0 ถึง 1 ระบุเศษส่วนของการเข้าชมที่เข้าร่วมในการทดสอบ เปลี่ยนแปลงสำหรับการทดสอบที่ดำเนินอยู่ได้ ไม่สามารถเปลี่ยนแปลงฟิลด์นี้ได้สำหรับการทดสอบที่มีสถานะ "ENDED" | เขียนได้ |
variations[] |
list |
อาร์เรย์ของรูปแบบ รูปแบบแรกในอาร์เรย์คือรูปแบบเดิม จำนวนรูปแบบจะไม่เปลี่ยนแปลงเมื่อการทดสอบอยู่ในสถานะ "ทำงาน" ต้องมีอย่างน้อย 2 รูปแบบก่อนจึงจะตั้งสถานะเป็น "ทำงาน" ได้ | เขียนได้ |
variations[].status |
string |
สถานะของรูปแบบ ค่าที่มีได้ ได้แก่ "ACTIVE", "INACTIVE" ระบบจะไม่แสดงรูปแบบที่ไม่ได้ใช้งาน ไม่สามารถเปลี่ยนแปลงฟิลด์นี้ได้สำหรับการทดสอบที่มีสถานะ "ENDED" | เขียนได้ |
variations[].url |
string |
URL ของรูปแบบ ไม่สามารถเปลี่ยนแปลงฟิลด์นี้ได้สำหรับการทดสอบที่มีสถานะ "กำลังทำงาน" หรือ "สิ้นสุด" | เขียนได้ |
winnerConfidenceLevel |
double |
จำนวนทศนิยมระหว่าง 0 ถึง 1 ระบุระดับความเชื่อมั่นที่จำเป็นในการเลือกผู้ชนะ ไม่สามารถเปลี่ยนแปลงฟิลด์นี้ได้สำหรับการทดสอบที่มีสถานะ "ENDED" | เขียนได้ |
คำตอบ
หากสำเร็จ เมธอดนี้จะแสดงผลทรัพยากรmanagement.experiment ในเนื้อหาการตอบกลับ
ตัวอย่าง
หมายเหตุ: ตัวอย่างโค้ดที่มีสำหรับวิธีการนี้ไม่ได้แสดงถึงภาษาโปรแกรมที่รองรับทั้งหมด (ดูรายการภาษาที่รองรับได้ในหน้าไลบรารีของไคลเอ็นต์)
Java
/* * Note: This code assumes you have an authorized Analytics service object. * See the Experiments Developer Guide for details. */ /* * This request creates a new Experiment. */ // Construct the body of the request. Experiment body = new Experiment(); body.setName("Landing Page Experiment"); body.setStatus("DRAFT"); // Construct the first variation. Variations variationA = new Variations(); variationA.setName("Variation A"); variationA.setUrl("index.html"); // Construct the second variation. Variations variationB = new Variations(); variationB.setName("Variation B"); variationB.setUrl("indexB.html"); // Set the variations. body.setVariations(Arrays.asList(variationA, variationB)); try { analytics.management().experiments().insert("123456", "UA-123456-1", "7654321", body).execute(); } catch (GoogleJsonResponseException e) { System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); }
PHP
/** * Note: This code assumes you have an authorized Analytics service object. * See the Experiments Developer Guide for details. */ /** * This request creates a new experiment. */ // Construct the body of the request. $experiment = new Google_Service_Analytics_Experiment(); $experiment->setName('Landing Page Experiment'); $experiment->setStatus('DRAFT'); // Construct the first variation. $variationA = new Google_Service_Analytics_ExperimentVariations(); $variationA->setName('VariationA'); $variationA->setUrl('index.html'); // Construct the second variation. $variationB = new Google_Service_Analytics_ExperimentVariations(); $variationB->setName('VariationB'); $variationB->setUrl('indexB.html'); // Set the variations. $experiment->setVariations(array($variationA, $variationB)); try { $analytics->management_experiments->insert('123456', 'UA-123456-1', '7654321', $experiment); } 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
# Note: This code assumes you have an authorized Analytics service object. # See the Experiments Developer Guide for details. # Example #1: # Creates a new DRAFT experiment with two variations. try: experiments = analytics.management().experiments().insert( accountId='123456', webPropertyId='UA-123456-1', profileId='98765432', body={ 'name': 'Landing Page Test', 'status': 'DRAFT', 'variations': [ { 'name': 'Variation A', 'url': 'index.html' }, { 'name': 'Variation B', 'url': 'indexB.html' } ] } ).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 Experiments Developer Guide for details. */ /* * This request creates a new Experiment. */ function insertExperiment() { var request = gapi.client.analytics.management.experiments.insert( { 'accountId': '123456', 'webPropertyId': 'UA-123456-1', 'profileId': '7654321', 'resource': { 'name': 'Landing Page Test', 'status': 'DRAFT', 'variations': [ { 'name': 'VariationA', 'url': 'index.html' }, { 'name': 'VariationB', 'url': 'indexB.html' } ] } }); request.execute(function (response) { // Handle the response. }); }