يجب تقديم تفويض.
إنشاء مقياس مخصَّص جديد جرِّبه الآن أو اطّلِع على مثال.
الطلب
طلب 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))
تجربة
استخدِم مستكشف واجهات برمجة التطبيقات أدناه لطلب هذه الطريقة على البيانات المباشرة والاطّلاع على الردّ. ويمكنك بدلاً من ذلك تجربة المستكشف المستقل.