Custom Metrics: insert

इसके लिए, अनुमति लेना ज़रूरी है

नई कस्टम मेट्रिक बनाएं. इसे अभी आज़माएं या उदाहरण देखें.

अनुरोध

एचटीटीपी अनुरोध

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))

इसे आज़माएं!

इस तरीके को लाइव डेटा पर कॉल करने और रिस्पॉन्स देखने के लिए, नीचे दिए गए एपीआई एक्सप्लोरर का इस्तेमाल करें. इसके अलावा, Standalone Explorer का इस्तेमाल भी किया जा सकता है.