خدمة "إحصاءات YouTube"
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تتيح لك خدمة "إحصاءات YouTube" استخدام
YouTube Analytics API في برمجة تطبيقات Google. تتيح واجهة برمجة التطبيقات هذه للمستخدمين استرداد إحصاءات المشاهدة ومقاييس الرواج والمعلومات الديمغرافية الخاصة بالفيديوهات والقنوات على YouTube.
للحصول على معلومات تفصيلية عن هذه الخدمة، يُرجى الاطّلاع على
المستندات المرجعية الخاصة
بـ YouTube Analytics API. مثل جميع الخدمات المتقدّمة في Apps Script، تستخدم خدمة "إحصاءات YouTube" العناصر والطرق والمعلَمات نفسها التي تستخدمها واجهة برمجة التطبيقات العامة. لمزيد من المعلومات، اطّلِع على كيفية تحديد التواقيع.
نموذج التعليمات البرمجية
يستخدم الرمز البرمجي النموذجي التالي الإصدار 2 من
YouTube Analytics API، بالإضافة إلى الإصدار 3 من YouTube
Data API، ويمكنك الوصول إليهما من خلال
خدمة YouTube في "برمجة تطبيقات Google".
للإبلاغ عن المشاكل والعثور على دعم آخر، يُرجى الاطّلاع على
دليل دعم YouTube API.
إنشاء تقرير
تنشئ هذه الدالة جدول بيانات يحتوي على عدد المشاهدات اليومية ومقاييس وقت المشاهدة وعدد المشتركين الجدد في فيديوهات القناة.
/** * Creates a spreadsheet containing daily view counts, watch-time metrics, * and new-subscriber counts for a channel's videos. */functioncreateReport(){// Retrieve info about the user's YouTube channel.constchannels=YouTube.Channels.list("id,contentDetails",{mine:true,});constchannelId=channels.items[0].id;// Retrieve analytics report for the channel.constoneMonthInMillis=1000*60*60*24*30;consttoday=newDate();constlastMonth=newDate(today.getTime()-oneMonthInMillis);constmetrics=["views","estimatedMinutesWatched","averageViewDuration","subscribersGained",];constresult=YouTubeAnalytics.Reports.query({ids:`channel==${channelId}`,startDate:formatDateString(lastMonth),endDate:formatDateString(today),metrics:metrics.join(","),dimensions:"day",sort:"day",});if(!result.rows){console.log("No rows returned.");return;}constspreadsheet=SpreadsheetApp.create("YouTube Analytics Report");constsheet=spreadsheet.getActiveSheet();// Append the headers.constheaders=result.columnHeaders.map((columnHeader)=>{returnformatColumnName(columnHeader.name);});sheet.appendRow(headers);// Append the results.sheet.getRange(2,1,result.rows.length,headers.length).setValues(result.rows);console.log("Report spreadsheet created: %s",spreadsheet.getUrl());}/** * Converts a Date object into a YYYY-MM-DD string. * @param {Date} date The date to convert to a string. * @return {string} The formatted date. */functionformatDateString(date){returnUtilities.formatDate(date,Session.getScriptTimeZone(),"yyyy-MM-dd");}/** * Formats a column name into a more human-friendly name. * @param {string} columnName The unprocessed name of the column. * @return {string} The formatted column name. * @example "averageViewPercentage" becomes "Average View Percentage". */functionformatColumnName(columnName){letname=columnName.replace(/([a-z])([A-Z])/g,"$1 $2");name=name.slice(0,1).toUpperCase()+name.slice(1);returnname;}
تاريخ التعديل الأخير: 2026-05-05 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2026-05-05 (حسب التوقيت العالمي المتفَّق عليه)"],[],[]]