অনুমোদন প্রয়োজন
একটি ভিউ (প্রোফাইল) এর জন্য রিয়েল-টাইম ডেটা প্রদান করে। এখন এটি চেষ্টা করুন বা একটি উদাহরণ দেখুন ।
অনুরোধ
HTTP অনুরোধ
GET https://www.googleapis.com/analytics/v3/data/realtime
পরামিতি
পরামিতি নাম | মান | বর্ণনা |
---|---|---|
প্রয়োজনীয় পরামিতি | ||
ids | string | Analytics ডেটা পুনরুদ্ধার করার জন্য অনন্য টেবিল আইডি। টেবিল আইডিটি ga:XXXX ফর্মের, যেখানে XXXX হল Analytics ভিউ (প্রোফাইল) আইডি৷ |
metrics | string | অ্যানালিটিক্স মেট্রিক্সের একটি কমা দ্বারা পৃথক করা তালিকা। যেমন, 'rt:activeUsers'। অন্তত একটি মেট্রিক নির্দিষ্ট করা আবশ্যক. |
ঐচ্ছিক পরামিতি | ||
dimensions | string | রিয়েল-টাইম মাত্রার একটি কমা-বিভক্ত তালিকা। যেমন, 'rt:medium,rt:city'। |
filters | string | রিয়েল-টাইম ডেটাতে প্রয়োগ করার জন্য মাত্রা বা মেট্রিক ফিল্টারগুলির একটি কমা দ্বারা পৃথক করা তালিকা৷ |
max-results | integer | এই ফিডে অন্তর্ভুক্ত করার জন্য সর্বাধিক সংখ্যক এন্ট্রি। |
sort | string | মাত্রা বা মেট্রিক্সের একটি কমা-বিভক্ত তালিকা যা রিয়েল-টাইম ডেটার জন্য সাজানোর ক্রম নির্ধারণ করে। |
অনুমোদন
এই অনুরোধের জন্য নিম্নলিখিত স্কোপের মধ্যে অন্তত একটির অনুমোদন প্রয়োজন ( প্রমাণিকরণ এবং অনুমোদন সম্পর্কে আরও পড়ুন )।
ব্যাপ্তি |
---|
https://www.googleapis.com/auth/analytics |
https://www.googleapis.com/auth/analytics.readonly |
শরীরের অনুরোধ
এই পদ্ধতির সাথে একটি অনুরোধ সংস্থা সরবরাহ করবেন না।
প্রতিক্রিয়া
সফল হলে, এই পদ্ধতিটি প্রতিক্রিয়া বডিতে একটি রিয়েল টাইম ডেটা রিসোর্স প্রদান করে।
উদাহরণ
দ্রষ্টব্য: এই পদ্ধতির জন্য উপলব্ধ কোড উদাহরণগুলি সমস্ত সমর্থিত প্রোগ্রামিং ভাষার প্রতিনিধিত্ব করে না (সমর্থিত ভাষার তালিকার জন্য ক্লায়েন্ট লাইব্রেরি পৃষ্ঠা দেখুন)।
জাভা
জাভা ক্লায়েন্ট লাইব্রেরি ব্যবহার করে
/**
* 1. Create and Execute a Real Time Report
* An application can request real-time data by calling the get method on the Analytics service object.
* The method requires an ids parameter which specifies from which view (profile) to retrieve data.
* For example, the following code requests real-time data for view (profile) ID 56789.
*/
Get realtimeRequest = analytics.data().realtime()
.get("ga:56789",
"rt:activeUsers")
.setDimensions("rt:medium");
try {
RealtimeData realtimeData = realtimeRequest.execute();
// Success.
} catch (GoogleJsonResponseException e) {
// Catch API specific errors.
handleApiError(e);
} catch (IOException e) {
// Catch general parsing network errors.
e.printStackTrace();
}
/**
* 2. Print out the Real-Time Data
* The components of the report can be printed out as follows:
*/
private void printRealtimeReport(RealtimeData realtimeData) {
System.out.println();
System.out.println("Response:");
System.out.println("ID:" + realtimeData.getId());
System.out.println("realtimeData Kind: " + realtimeData.getKind());
System.out.println();
printQueryInfo(realtimeData.getQuery());
printProfileInfo(realtimeData.getProfileInfo());
printPaginationInfo(realtimeData);
printDataTable(realtimeData);
}
private void printQueryInfo(Query query) {
System.out.println("Query Info:");
System.out.println("Ids: " + query.getIds());
System.out.println("Metrics: " + query.getMetrics());
System.out.println("Dimensions: " + query.getDimensions());
System.out.println("Sort: " + query.getSort());
System.out.println("Filters: " + query.getFilters());
System.out.println("Max results: " + query.getMaxResults());
System.out.println();
}
private void printProfileInfo(ProfileInfo profileInfo) {
System.out.println("Info:");
System.out.println("Account ID:" + profileInfo.getAccountId());
System.out.println("Web Property ID:" + profileInfo.getWebPropertyId());
System.out.println("Profile ID:" + profileInfo.getProfileId());
System.out.println("Profile Name:" + profileInfo.getProfileName());
System.out.println("Table Id:" + profileInfo.getTableId());
System.out.println();
}
private void printPaginationInfo(RealtimeData realtimeData) {
System.out.println("Pagination info:");
System.out.println("Self link: " + realtimeData.getSelfLink());
System.out.println("Total Results: " + realtimeData.getTotalResults());
System.out.println();
}
private void printDataTable(RealtimeData realtimeData) {
if (realtimeData.getTotalResults() > 0) {
System.out.println("Data Table:");
for (ColumnHeaders header : realtimeData.getColumnHeaders()) {
System.out.format("%-32s", header.getName() + '(' + header.getDataType() + ')');
}
System.out.println();
for (List<String> row : realtimeData.getRows()) {
for (String element : row) {
System.out.format("%-32s", element);
}
System.out.println();
}
} else {
System.out.println("No data");
}
}
পিএইচপি
পিএইচপি ক্লায়েন্ট লাইব্রেরি ব্যবহার করে
/** * 1.Create and Execute a Real Time Report * An application can request real-time data by calling the get method on the Analytics service object. * The method requires an ids parameter which specifies from which view (profile) to retrieve data. * For example, the following code requests real-time data for view (profile) ID 56789. */ $optParams = array( 'dimensions' => 'rt:medium'); try { $results = $analytics->data_realtime->get( 'ga:56789', 'rt:activeUsers', $optParams); // Success. } catch (apiServiceException $e) { // Handle API service exceptions. $error = $e->getMessage(); } /** * 2. Print out the Real-Time Data * The components of the report can be printed out as follows: */ function printRealtimeReport($results) { printReportInfo($results); printQueryInfo($results); printProfileInfo($results); printColumnHeaders($results); printDataTable($results); printTotalsForAllResults($results); } function printDataTable(&$results) { if (count($results->getRows()) > 0) { $table .= '<table>'; // Print headers. $table .= '<tr>'; foreach ($results->getColumnHeaders() as $header) { $table .= '<th>' . $header->name . '</th>'; } $table .= '</tr>'; // Print table rows. foreach ($results->getRows() as $row) { $table .= '<tr>'; foreach ($row as $cell) { $table .= '<td>' . htmlspecialchars($cell, ENT_NOQUOTES) . '</td>'; } $table .= '</tr>'; } $table .= '</table>'; } else { $table .= '<p>No Results Found.</p>'; } print $table; } function printColumnHeaders(&$results) { $html = ''; $headers = $results->getColumnHeaders(); foreach ($headers as $header) { $html .= <<<HTML <pre> Column Name = {$header->getName()} Column Type = {$header->getColumnType()} Column Data Type = {$header->getDataType()} </pre> HTML; } print $html; } function printQueryInfo(&$results) { $query = $results->getQuery(); $html = <<<HTML <pre> Ids = {$query->getIds()} Metrics = {$query->getMetrics()} Dimensions = {$query->getDimensions()} Sort = {$query->getSort()} Filters = {$query->getFilters()} Max Results = {$query->getMax_results()} </pre> HTML; print $html; } function printProfileInfo(&$results) { $profileInfo = $results->getProfileInfo(); $html = <<<HTML <pre> Account ID = {$profileInfo->getAccountId()} Web Property ID = {$profileInfo->getWebPropertyId()} Internal Web Property ID = {$profileInfo->getInternalWebPropertyId()} Profile ID = {$profileInfo->getProfileId()} Profile Name = {$profileInfo->getProfileName()} Table ID = {$profileInfo->getTableId()} </pre> HTML; print $html; } function printReportInfo(&$results) { $html = <<<HTML <pre> Kind = {$results->getKind()} ID = {$results->getId()} Self Link = {$results->getSelfLink()} Total Results = {$results->getTotalResults()} </pre> HTML; print $html; } function printTotalsForAllResults(&$results) { $totals = $results->getTotalsForAllResults(); foreach ($totals as $metricName => $metricTotal) { $html .= "Metric Name = $metricName\n"; $html .= "Metric Total = $metricTotal"; } print $html; }
পাইথন
পাইথন ক্লায়েন্ট লাইব্রেরি ব্যবহার করে
# 1. Create and Execute a Real Time Report # An application can request real-time data by calling the get method on the Analytics service object. # The method requires an ids parameter which specifies from which view (profile) to retrieve data. # For example, the following code requests real-time data for view (profile) ID 56789. try: service.data().realtime().get( ids='ga:56789', metrics='rt:activeUsers', dimensions='rt:medium').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 ('Arg, there was an API error : %s : %s' % (error.resp.status, error._get_reason())) # 2. Print out the Real-Time Data # The components of the report can be printed out as follows: def print_realtime_report(results): print '**Real-Time Report Response**' print_report_info(results) print_query_info(results.get('query')) print_profile_info(results.get('profileInfo')) print_column_headers(results.get('columnHeaders')) print_data_table(results) print_totals_for_all_results(results) def print_data_table(results): print 'Data Table:' # Print headers. output = [] for header in results.get('columnHeaders'): output.append('%30s' % header.get('name')) print ''.join(output) # Print rows. if results.get('rows', []): for row in results.get('rows'): output = [] for cell in row: output.append('%30s' % cell) print ''.join(output) else: print 'No Results Found' def print_column_headers(headers): print 'Column Headers:' for header in headers: print 'Column name = %s' % header.get('name') print 'Column Type = %s' % header.get('columnType') print 'Column Data Type = %s' % header.get('dataType') def print_query_info(query): if query: print 'Query Info:' print 'Ids = %s' % query.get('ids') print 'Metrics: = %s' % query.get('metrics') print 'Dimensions = %s' % query.get('dimensions') print 'Sort = %s' % query.get('sort') print 'Filters = %s' % query.get('filters') print 'Max results = %s' % query.get('max-results') def print_profile_info(profile_info): if profile_info: print 'Profile Info:' print 'Account ID = %s' % profile_info.get('accountId') print 'Web Property ID = %s' % profile_info.get('webPropertyId') print 'Profile ID = %s' % profile_info.get('profileId') print 'Profile Name = %s' % profile_info.get('profileName') print 'Table Id = %s' % profile_info.get('tableId') def print_report_info(results): print 'Kind = %s' % results.get('kind') print 'ID = %s' % results.get('id') print 'Self Link = %s' % results.get('selfLink') print 'Total Results = %s' % results.get('totalResults') def print_totals_for_all_results(results): totals = results.get('totalsForAllResults') for metric_name, metric_total in totals.iteritems(): print 'Metric Name = %s' % metric_name print 'Metric Total = %s' % metric_total
এটা চেষ্টা করুন!
লাইভ ডেটাতে এই পদ্ধতিতে কল করতে এবং প্রতিক্রিয়া দেখতে নীচের APIs এক্সপ্লোরার ব্যবহার করুন। বিকল্পভাবে, স্বতন্ত্র এক্সপ্লোরার ব্যবহার করে দেখুন।
অনুমোদন প্রয়োজন
একটি ভিউ (প্রোফাইল) এর জন্য রিয়েল-টাইম ডেটা প্রদান করে। এখন এটি চেষ্টা করুন বা একটি উদাহরণ দেখুন ।
অনুরোধ
HTTP অনুরোধ
GET https://www.googleapis.com/analytics/v3/data/realtime
পরামিতি
পরামিতি নাম | মান | বর্ণনা |
---|---|---|
প্রয়োজনীয় পরামিতি | ||
ids | string | Analytics ডেটা পুনরুদ্ধার করার জন্য অনন্য টেবিল আইডি। টেবিল আইডিটি ga:XXXX ফর্মের, যেখানে XXXX হল Analytics ভিউ (প্রোফাইল) আইডি৷ |
metrics | string | অ্যানালিটিক্স মেট্রিক্সের একটি কমা দ্বারা পৃথক করা তালিকা। যেমন, 'rt:activeUsers'। অন্তত একটি মেট্রিক নির্দিষ্ট করা আবশ্যক. |
ঐচ্ছিক পরামিতি | ||
dimensions | string | রিয়েল-টাইম মাত্রার একটি কমা-বিভক্ত তালিকা। যেমন, 'rt:medium,rt:city'। |
filters | string | রিয়েল-টাইম ডেটাতে প্রয়োগ করার জন্য মাত্রা বা মেট্রিক ফিল্টারগুলির একটি কমা দ্বারা পৃথক করা তালিকা৷ |
max-results | integer | এই ফিডে অন্তর্ভুক্ত করার জন্য সর্বাধিক সংখ্যক এন্ট্রি। |
sort | string | মাত্রা বা মেট্রিক্সের একটি কমা-বিভক্ত তালিকা যা রিয়েল-টাইম ডেটার জন্য সাজানোর ক্রম নির্ধারণ করে। |
অনুমোদন
এই অনুরোধের জন্য নিম্নলিখিত স্কোপের মধ্যে অন্তত একটির অনুমোদন প্রয়োজন ( প্রমাণিকরণ এবং অনুমোদন সম্পর্কে আরও পড়ুন )।
ব্যাপ্তি |
---|
https://www.googleapis.com/auth/analytics |
https://www.googleapis.com/auth/analytics.readonly |
শরীরের অনুরোধ
এই পদ্ধতির সাথে একটি অনুরোধ সংস্থা সরবরাহ করবেন না।
প্রতিক্রিয়া
সফল হলে, এই পদ্ধতিটি প্রতিক্রিয়া বডিতে একটি রিয়েল টাইম ডেটা রিসোর্স প্রদান করে।
উদাহরণ
দ্রষ্টব্য: এই পদ্ধতির জন্য উপলব্ধ কোড উদাহরণগুলি সমস্ত সমর্থিত প্রোগ্রামিং ভাষার প্রতিনিধিত্ব করে না (সমর্থিত ভাষার তালিকার জন্য ক্লায়েন্ট লাইব্রেরি পৃষ্ঠা দেখুন)।
জাভা
জাভা ক্লায়েন্ট লাইব্রেরি ব্যবহার করে
/**
* 1. Create and Execute a Real Time Report
* An application can request real-time data by calling the get method on the Analytics service object.
* The method requires an ids parameter which specifies from which view (profile) to retrieve data.
* For example, the following code requests real-time data for view (profile) ID 56789.
*/
Get realtimeRequest = analytics.data().realtime()
.get("ga:56789",
"rt:activeUsers")
.setDimensions("rt:medium");
try {
RealtimeData realtimeData = realtimeRequest.execute();
// Success.
} catch (GoogleJsonResponseException e) {
// Catch API specific errors.
handleApiError(e);
} catch (IOException e) {
// Catch general parsing network errors.
e.printStackTrace();
}
/**
* 2. Print out the Real-Time Data
* The components of the report can be printed out as follows:
*/
private void printRealtimeReport(RealtimeData realtimeData) {
System.out.println();
System.out.println("Response:");
System.out.println("ID:" + realtimeData.getId());
System.out.println("realtimeData Kind: " + realtimeData.getKind());
System.out.println();
printQueryInfo(realtimeData.getQuery());
printProfileInfo(realtimeData.getProfileInfo());
printPaginationInfo(realtimeData);
printDataTable(realtimeData);
}
private void printQueryInfo(Query query) {
System.out.println("Query Info:");
System.out.println("Ids: " + query.getIds());
System.out.println("Metrics: " + query.getMetrics());
System.out.println("Dimensions: " + query.getDimensions());
System.out.println("Sort: " + query.getSort());
System.out.println("Filters: " + query.getFilters());
System.out.println("Max results: " + query.getMaxResults());
System.out.println();
}
private void printProfileInfo(ProfileInfo profileInfo) {
System.out.println("Info:");
System.out.println("Account ID:" + profileInfo.getAccountId());
System.out.println("Web Property ID:" + profileInfo.getWebPropertyId());
System.out.println("Profile ID:" + profileInfo.getProfileId());
System.out.println("Profile Name:" + profileInfo.getProfileName());
System.out.println("Table Id:" + profileInfo.getTableId());
System.out.println();
}
private void printPaginationInfo(RealtimeData realtimeData) {
System.out.println("Pagination info:");
System.out.println("Self link: " + realtimeData.getSelfLink());
System.out.println("Total Results: " + realtimeData.getTotalResults());
System.out.println();
}
private void printDataTable(RealtimeData realtimeData) {
if (realtimeData.getTotalResults() > 0) {
System.out.println("Data Table:");
for (ColumnHeaders header : realtimeData.getColumnHeaders()) {
System.out.format("%-32s", header.getName() + '(' + header.getDataType() + ')');
}
System.out.println();
for (List<String> row : realtimeData.getRows()) {
for (String element : row) {
System.out.format("%-32s", element);
}
System.out.println();
}
} else {
System.out.println("No data");
}
}
পিএইচপি
পিএইচপি ক্লায়েন্ট লাইব্রেরি ব্যবহার করে
/** * 1.Create and Execute a Real Time Report * An application can request real-time data by calling the get method on the Analytics service object. * The method requires an ids parameter which specifies from which view (profile) to retrieve data. * For example, the following code requests real-time data for view (profile) ID 56789. */ $optParams = array( 'dimensions' => 'rt:medium'); try { $results = $analytics->data_realtime->get( 'ga:56789', 'rt:activeUsers', $optParams); // Success. } catch (apiServiceException $e) { // Handle API service exceptions. $error = $e->getMessage(); } /** * 2. Print out the Real-Time Data * The components of the report can be printed out as follows: */ function printRealtimeReport($results) { printReportInfo($results); printQueryInfo($results); printProfileInfo($results); printColumnHeaders($results); printDataTable($results); printTotalsForAllResults($results); } function printDataTable(&$results) { if (count($results->getRows()) > 0) { $table .= '<table>'; // Print headers. $table .= '<tr>'; foreach ($results->getColumnHeaders() as $header) { $table .= '<th>' . $header->name . '</th>'; } $table .= '</tr>'; // Print table rows. foreach ($results->getRows() as $row) { $table .= '<tr>'; foreach ($row as $cell) { $table .= '<td>' . htmlspecialchars($cell, ENT_NOQUOTES) . '</td>'; } $table .= '</tr>'; } $table .= '</table>'; } else { $table .= '<p>No Results Found.</p>'; } print $table; } function printColumnHeaders(&$results) { $html = ''; $headers = $results->getColumnHeaders(); foreach ($headers as $header) { $html .= <<<HTML <pre> Column Name = {$header->getName()} Column Type = {$header->getColumnType()} Column Data Type = {$header->getDataType()} </pre> HTML; } print $html; } function printQueryInfo(&$results) { $query = $results->getQuery(); $html = <<<HTML <pre> Ids = {$query->getIds()} Metrics = {$query->getMetrics()} Dimensions = {$query->getDimensions()} Sort = {$query->getSort()} Filters = {$query->getFilters()} Max Results = {$query->getMax_results()} </pre> HTML; print $html; } function printProfileInfo(&$results) { $profileInfo = $results->getProfileInfo(); $html = <<<HTML <pre> Account ID = {$profileInfo->getAccountId()} Web Property ID = {$profileInfo->getWebPropertyId()} Internal Web Property ID = {$profileInfo->getInternalWebPropertyId()} Profile ID = {$profileInfo->getProfileId()} Profile Name = {$profileInfo->getProfileName()} Table ID = {$profileInfo->getTableId()} </pre> HTML; print $html; } function printReportInfo(&$results) { $html = <<<HTML <pre> Kind = {$results->getKind()} ID = {$results->getId()} Self Link = {$results->getSelfLink()} Total Results = {$results->getTotalResults()} </pre> HTML; print $html; } function printTotalsForAllResults(&$results) { $totals = $results->getTotalsForAllResults(); foreach ($totals as $metricName => $metricTotal) { $html .= "Metric Name = $metricName\n"; $html .= "Metric Total = $metricTotal"; } print $html; }
পাইথন
পাইথন ক্লায়েন্ট লাইব্রেরি ব্যবহার করে
# 1. Create and Execute a Real Time Report # An application can request real-time data by calling the get method on the Analytics service object. # The method requires an ids parameter which specifies from which view (profile) to retrieve data. # For example, the following code requests real-time data for view (profile) ID 56789. try: service.data().realtime().get( ids='ga:56789', metrics='rt:activeUsers', dimensions='rt:medium').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 ('Arg, there was an API error : %s : %s' % (error.resp.status, error._get_reason())) # 2. Print out the Real-Time Data # The components of the report can be printed out as follows: def print_realtime_report(results): print '**Real-Time Report Response**' print_report_info(results) print_query_info(results.get('query')) print_profile_info(results.get('profileInfo')) print_column_headers(results.get('columnHeaders')) print_data_table(results) print_totals_for_all_results(results) def print_data_table(results): print 'Data Table:' # Print headers. output = [] for header in results.get('columnHeaders'): output.append('%30s' % header.get('name')) print ''.join(output) # Print rows. if results.get('rows', []): for row in results.get('rows'): output = [] for cell in row: output.append('%30s' % cell) print ''.join(output) else: print 'No Results Found' def print_column_headers(headers): print 'Column Headers:' for header in headers: print 'Column name = %s' % header.get('name') print 'Column Type = %s' % header.get('columnType') print 'Column Data Type = %s' % header.get('dataType') def print_query_info(query): if query: print 'Query Info:' print 'Ids = %s' % query.get('ids') print 'Metrics: = %s' % query.get('metrics') print 'Dimensions = %s' % query.get('dimensions') print 'Sort = %s' % query.get('sort') print 'Filters = %s' % query.get('filters') print 'Max results = %s' % query.get('max-results') def print_profile_info(profile_info): if profile_info: print 'Profile Info:' print 'Account ID = %s' % profile_info.get('accountId') print 'Web Property ID = %s' % profile_info.get('webPropertyId') print 'Profile ID = %s' % profile_info.get('profileId') print 'Profile Name = %s' % profile_info.get('profileName') print 'Table Id = %s' % profile_info.get('tableId') def print_report_info(results): print 'Kind = %s' % results.get('kind') print 'ID = %s' % results.get('id') print 'Self Link = %s' % results.get('selfLink') print 'Total Results = %s' % results.get('totalResults') def print_totals_for_all_results(results): totals = results.get('totalsForAllResults') for metric_name, metric_total in totals.iteritems(): print 'Metric Name = %s' % metric_name print 'Metric Total = %s' % metric_total
এটা চেষ্টা করুন!
লাইভ ডেটাতে এই পদ্ধতিতে কল করতে এবং প্রতিক্রিয়া দেখতে নীচের APIs এক্সপ্লোরার ব্যবহার করুন। বিকল্পভাবে, স্বতন্ত্র এক্সপ্লোরার ব্যবহার করে দেখুন।