Experiments: insert

נדרשת הרשאה

יוצרים ניסוי חדש. להצגת דוגמה

בנוסף לפרמטרים הרגילים, השיטה הזו תומכת בפרמטרים המפורטים בטבלת הפרמטרים.

בקשה

בקשת HTTP

POST https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/profiles/profileId/experiments

פרמטרים

שם הפרמטר ערך תיאור
פרמטרים של נתיב
accountId string מספר החשבון שעבורו רוצים ליצור את הניסוי.
profileId string מזהה התצוגה המפורטת (פרופיל) שעבורו יש ליצור את הניסוי.
webPropertyId string מזהה נכס האינטרנט שעבורו רוצים ליצור את הניסוי.

אישור

בקשה זו מחייבת הרשאה עם לפחות אחד מההיקפים הבאים (מידע נוסף על אימות והרשאה).

היקף
https://www.googleapis.com/auth/analytics
https://www.googleapis.com/auth/analytics.edit

גוף הבקשה

בגוף הבקשה, מספקים משאבmanagement.experiment עם המאפיינים הבאים:

שם הנכס ערך תיאור הערות
המאפיינים הנדרשים
name string שם הניסוי. לא ניתן לשנות שדה זה עבור ניסוי שהסטטוס שלו הוא ENDED. חובה למלא את השדה הזה כשיוצרים ניסוי. ניתן לכתיבה
status string סטטוס הניסוי. ערכים אפשריים: "DRAFT", "READY_TO_RUN", "RUNNING", "ENDED". ניתן ליצור ניסויים במצב 'DRAFT', 'READY_TO_RUN' או 'RUNNING'. חובה למלא את השדה הזה כשיוצרים ניסוי. ניתן לכתיבה
variations[].name string שם הווריאציה. חובה למלא את השדה הזה כשיוצרים ניסוי. לא ניתן לשנות שדה זה עבור ניסוי שהסטטוס שלו הוא ENDED. ניתן לכתיבה
מאפיינים אופציונליים
description string הערות לגבי הניסוי הזה. ניתן לכתיבה
editableInGaUi boolean אם הערך הוא True, משתמש הקצה יוכל לערוך את הניסוי דרך ממשק המשתמש של Google Analytics. ניתן לכתיבה
equalWeighting boolean ערך בוליאני שמציין אם לחלק את התנועה באופן שווה בין כל הווריאציות. אם הערך הוא False, ניסויי תוכן יפעלו בהתאם להתנהגות ברירת המחדל של התאמה דינמית של התנועה על סמך ביצועי הגרסה. אופציונלי – ברירת המחדל היא False. לא ניתן לשנות שדה זה עבור ניסוי שהסטטוס שלו הוא 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"". השדה הזה נדרש אם הסטטוס הוא RUNNING ו-servingFramework הוא אחד מהערכים 'REDIRECT' או 'API'. ניתן לכתיבה
optimizationType string האם צריך למזער או להגדיל את מדד האובייקט. ערכים אפשריים: "max", "Minimum". אופציונלי - ברירת המחדל היא "max". לא ניתן לציין ללא objectMetric. לא ניתן לשנות כאשר הסטטוס הוא 'RUNNING' או 'ENDED'. ניתן לכתיבה
rewriteVariationUrlsAsOriginal boolean ערך בוליאני שמציין אם כתובות URL של וריאציות נכתבות מחדש כדי להתאים לאלו של המקור. לא ניתן לשנות שדה זה עבור ניסוי שהסטטוס שלו הוא ENDED. ניתן לכתיבה
servingFramework string המסגרת המשמשת להצגת הווריאציות של הניסוי ולהערכת התוצאות. אחת מהאפשרויות:
  • הפניה מחדש: Google Analytics מפנה תנועה לדפי גרסאות שונים, מדווח על הווריאציה שנבחרה ומעריך את התוצאות.
  • API: מערכת Google Analytics בוחרת את הווריאציה כדי להציג אותה ומדווחת עליה, ומבצעת הערכה של התוצאות. מבצע הקריאה החוזרת הוא האחראי להצגת הווריאציה שנבחרה.
  • EXTERNAL: הווריאציות יוצגו באופן חיצוני והגרסה שנבחרה תדווח ל-Google Analytics. מבצע הקריאה החוזרת אחראי להציג את הווריאציה שנבחרה ולהעריך את התוצאות.
ניתן לכתיבה
trafficCoverage double מספר נקודה צפה (floating-point) בין 0 ל-1. מציין את החלק מתוך התנועה שמשתתפת בניסוי. ניתן לשנות את זה בניסוי פעיל. לא ניתן לשנות שדה זה עבור ניסוי שהסטטוס שלו הוא ENDED. ניתן לכתיבה
variations[] list מערך של וריאציות. הווריאציה הראשונה של המערך היא המקורית. מספר הווריאציות לא יכול להשתנות לאחר שהניסוי נמצא במצב RUNNING. יש צורך בשתי וריאציות לפחות כדי להגדיר את הסטטוס ל'פועל'. ניתן לכתיבה
variations[].status string הסטטוס של הווריאציה. ערכים אפשריים: "ACTIVE", "INACTIVE". גרסאות לא פעילות לא מוצגות. לא ניתן לשנות שדה זה עבור ניסוי שהסטטוס שלו הוא ENDED. ניתן לכתיבה
variations[].url string כתובת ה-URL של הווריאציה. לא ניתן לשנות את השדה הזה עבור ניסוי שהסטטוס שלו הוא 'פועל' או 'הסתיים'. ניתן לכתיבה
winnerConfidenceLevel double מספר נקודה צפה (floating-point) בין 0 ל-1. מציין את רמת הסמך הדרושה לבחירת גרסה מנצחת. לא ניתן לשנות שדה זה עבור ניסוי שהסטטוס שלו הוא ENDED. ניתן לכתיבה

תשובה

אם הפעולה בוצעה בהצלחה, השיטה הזו מחזירה משאב management.experiment בגוף התגובה.

דוגמאות

הערה: דוגמאות הקוד הזמינות לשיטה זו לא מייצגות את כל שפות התכנות הנתמכות (רשימת השפות הנתמכות זמינה בדף של ספריות המשתמשים).

Java

משתמש בספריית הלקוח של 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

משתמש בספריית הלקוח של 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

משתמש בספריית הלקוח של 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. });
}