Custom Metrics: insert

נדרשת הרשאה

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

בקשה

בקשת HTTP

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

פרמטרים

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

אישור

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

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

גוף הבקשה

בגוף הבקשה, מציינים משאב Management.customMetric.

תשובה

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

דוגמאות

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

Java

משתמש בספריית הלקוח של Java.

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

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

// Construct the body of the request and set its properties.
CustomMetric body = new CustomMetric();
body.setName("Level Completions");
body.setScope("HIT");
body.setType("INTEGER");
body.setActive(true);

try {
  analytics.management().customMetrics()
      .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 metric.
try:
  analytics.management().customMetrics().insert(
      accountId='123456',
      webPropertyId='UA-123456-1',
      body={
          'name': 'Level Completions',
          'scope': 'HIT',
          'type': 'INTEGER',
          '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))

רוצה לנסות?

צריך להשתמש ב-APIs Explorer שבהמשך כדי לקרוא לשיטה הזו בנתונים בזמן אמת ולראות את התגובה. לחלופין, אפשר לנסות את ה-Explorer העצמאי.