每小时的页面访问统计报告

时间:2018-07-24 22:33:00

标签: php google-analytics google-analytics-api

我正在尝试获取每小时级别的页面访问统计信息,我在下面编写了代码预览,但是从Analytics api获得的响应(我在下面转储)不包含任何此类统计信息,并且即使我将小时尺寸更改为每天,它也没有任何改变。有人可以寄给我可以执行此操作的已修复代码吗?。

代码

$dateRange_7days = new \Google_Service_AnalyticsReporting_DateRange();
$dateRange_7days->setStartDate("2daysAgo");
$dateRange_7days->setEndDate("today");

$sessions_7days = new \Google_Service_AnalyticsReporting_Metric();
$sessions_7days->setExpression("ga:sessions");
$sessions_7days->setAlias("sessions");

$users_7days = new \Google_Service_AnalyticsReporting_Metric();
$users_7days->setExpression("ga:users");
$users_7days->setAlias("users");

$dimensions_7days = new \Google_Service_AnalyticsReporting_Dimension();
$dimensions_7days->setName("ga:hour");

$request_7days = new \Google_Service_AnalyticsReporting_ReportRequest();
$request_7days->setViewId($VIEW_ID);
$request_7days->setDateRanges($dateRange_7days);
$request_7days->setMetrics(array($sessions_7days, $users_7days));
$request_7days->setDimensions($dimensions_7days);

$body_7days = new \Google_Service_AnalyticsReporting_GetReportsRequest();
$body_7days->setReportRequests( array( $request_7days) );

转储

array:1 [▼
  0 => Google_Service_AnalyticsReporting_GetReportsResponse {#601 ▼
    #collection_key: "reports"
    +queryCost: null
    #reportsType: "Google_Service_AnalyticsReporting_Report"
    #reportsDataType: "array"
    #resourceQuotasRemainingType: "Google_Service_AnalyticsReporting_ResourceQuotasRemaining"
    #resourceQuotasRemainingDataType: ""
    #internal_gapi_mappings: []
    #modelData: []
    #processed: []
    +"reports": array:1 [▼
      0 => Google_Service_AnalyticsReporting_Report {#503 ▼
        #columnHeaderType: "Google_Service_AnalyticsReporting_ColumnHeader"
        #columnHeaderDataType: ""
        #dataType: "Google_Service_AnalyticsReporting_ReportData"
        #dataDataType: ""
        +nextPageToken: null
        #internal_gapi_mappings: []
        #modelData: []
        #processed: []
        +"columnHeader": Google_Service_AnalyticsReporting_ColumnHeader {#545 ▼
          #collection_key: "dimensions"
          +dimensions: array:1 [▼
            0 => "ga:hour"
          ]
          #metricHeaderType: "Google_Service_AnalyticsReporting_MetricHeader"
          #metricHeaderDataType: ""
          #internal_gapi_mappings: []
          #modelData: []
          #processed: []
          +"metricHeader": Google_Service_AnalyticsReporting_MetricHeader {#602 ▼
            #collection_key: "pivotHeaders"
            #metricHeaderEntriesType: "Google_Service_AnalyticsReporting_MetricHeaderEntry"
            #metricHeaderEntriesDataType: "array"
            #pivotHeadersType: "Google_Service_AnalyticsReporting_PivotHeader"
            #pivotHeadersDataType: "array"
            #internal_gapi_mappings: []
            #modelData: []
            #processed: []
            +"metricHeaderEntries": array:2 [▼
              0 => Google_Service_AnalyticsReporting_MetricHeaderEntry {#599 ▼
                +name: "sessions"
                +type: "INTEGER"
                #internal_gapi_mappings: []
                #modelData: []
                #processed: []
              }
              1 => Google_Service_AnalyticsReporting_MetricHeaderEntry {#571 ▼
                +name: "users"
                +type: "INTEGER"
                #internal_gapi_mappings: []
                #modelData: []
                #processed: []
              }
            ]
          }
        }
        +"data": Google_Service_AnalyticsReporting_ReportData {#619 ▼
          #collection_key: "totals"
          +dataLastRefreshed: null
          +isDataGolden: null
          #maximumsType: "Google_Service_AnalyticsReporting_DateRangeValues"
          #maximumsDataType: "array"
          #minimumsType: "Google_Service_AnalyticsReporting_DateRangeValues"
          #minimumsDataType: "array"
          +rowCount: 13
          #rowsType: "Google_Service_AnalyticsReporting_ReportRow"
          #rowsDataType: "array"
          +samplesReadCounts: null
          +samplingSpaceSizes: null
          #totalsType: "Google_Service_AnalyticsReporting_DateRangeValues"
          #totalsDataType: "array"
          #internal_gapi_mappings: []
          #modelData: []
          #processed: []
          +"rows": array:13 [▼
            0 => Google_Service_AnalyticsReporting_ReportRow {#555 ▼
              #collection_key: "metrics"
              +dimensions: array:1 [▼
                0 => "00"
              ]
              #metricsType: "Google_Service_AnalyticsReporting_DateRangeValues"
              #metricsDataType: "array"
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
              +"metrics": array:1 [▼
                0 => Google_Service_AnalyticsReporting_DateRangeValues {#562 ▼
                  #collection_key: "values"
                  #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
                  #pivotValueRegionsDataType: "array"
                  +values: array:2 [▼
                    0 => "4"
                    1 => "2"
                  ]
                  #internal_gapi_mappings: []
                  #modelData: []
                  #processed: []
                }
              ]
            }
            1 => Google_Service_AnalyticsReporting_ReportRow {#507 ▼
              #collection_key: "metrics"
              +dimensions: array:1 [▼
                0 => "01"
              ]
              #metricsType: "Google_Service_AnalyticsReporting_DateRangeValues"
              #metricsDataType: "array"
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
              +"metrics": array:1 [▼
                0 => Google_Service_AnalyticsReporting_DateRangeValues {#618 ▼
                  #collection_key: "values"
                  #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
                  #pivotValueRegionsDataType: "array"
                  +values: array:2 [▼
                    0 => "2"
                    1 => "2"
                  ]
                  #internal_gapi_mappings: []
                  #modelData: []
                  #processed: []
                }
              ]
            }
            2 => Google_Service_AnalyticsReporting_ReportRow {#617 ▼
              #collection_key: "metrics"
              +dimensions: array:1 [▼
                0 => "02"
              ]
              #metricsType: "Google_Service_AnalyticsReporting_DateRangeValues"
              #metricsDataType: "array"
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
              +"metrics": array:1 [▼
                0 => Google_Service_AnalyticsReporting_DateRangeValues {#616 ▼
                  #collection_key: "values"
                  #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
                  #pivotValueRegionsDataType: "array"
                  +values: array:2 [▼
                    0 => "2"
                    1 => "2"
                  ]
                  #internal_gapi_mappings: []
                  #modelData: []
                  #processed: []
                }
              ]
            }
            3 => Google_Service_AnalyticsReporting_ReportRow {#615 ▼
              #collection_key: "metrics"
              +dimensions: array:1 [▼
                0 => "03"
              ]
              #metricsType: "Google_Service_AnalyticsReporting_DateRangeValues"
              #metricsDataType: "array"
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
              +"metrics": array:1 [▼
                0 => Google_Service_AnalyticsReporting_DateRangeValues {#614 ▼
                  #collection_key: "values"
                  #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
                  #pivotValueRegionsDataType: "array"
                  +values: array:2 [▼
                    0 => "1"
                    1 => "1"
                  ]
                  #internal_gapi_mappings: []
                  #modelData: []
                  #processed: []
                }
              ]
            }
            4 => Google_Service_AnalyticsReporting_ReportRow {#613 ▼
              #collection_key: "metrics"
              +dimensions: array:1 [▼
                0 => "04"
              ]
              #metricsType: "Google_Service_AnalyticsReporting_DateRangeValues"
              #metricsDataType: "array"
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
              +"metrics": array:1 [▼
                0 => Google_Service_AnalyticsReporting_DateRangeValues {#612 ▼
                  #collection_key: "values"
                  #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
                  #pivotValueRegionsDataType: "array"
                  +values: array:2 [▼
                    0 => "1"
                    1 => "1"
                  ]
                  #internal_gapi_mappings: []
                  #modelData: []
                  #processed: []
                }
              ]
            }
            5 => Google_Service_AnalyticsReporting_ReportRow {#611 ▼
              #collection_key: "metrics"
              +dimensions: array:1 [▼
                0 => "05"
              ]
              #metricsType: "Google_Service_AnalyticsReporting_DateRangeValues"
              #metricsDataType: "array"
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
              +"metrics": array:1 [▼
                0 => Google_Service_AnalyticsReporting_DateRangeValues {#610 ▼
                  #collection_key: "values"
                  #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
                  #pivotValueRegionsDataType: "array"
                  +values: array:2 [▼
                    0 => "1"
                    1 => "1"
                  ]
                  #internal_gapi_mappings: []
                  #modelData: []
                  #processed: []
                }
              ]
            }
            6 => Google_Service_AnalyticsReporting_ReportRow {#609 ▼
              #collection_key: "metrics"
              +dimensions: array:1 [▼
                0 => "12"
              ]
              #metricsType: "Google_Service_AnalyticsReporting_DateRangeValues"
              #metricsDataType: "array"
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
              +"metrics": array:1 [▼
                0 => Google_Service_AnalyticsReporting_DateRangeValues {#608 ▼
                  #collection_key: "values"
                  #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
                  #pivotValueRegionsDataType: "array"
                  +values: array:2 [▼
                    0 => "1"
                    1 => "1"
                  ]
                  #internal_gapi_mappings: []
                  #modelData: []
                  #processed: []
                }
              ]
            }
            7 => Google_Service_AnalyticsReporting_ReportRow {#607 ▼
              #collection_key: "metrics"
              +dimensions: array:1 [▼
                0 => "14"
              ]
              #metricsType: "Google_Service_AnalyticsReporting_DateRangeValues"
              #metricsDataType: "array"
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
              +"metrics": array:1 [▼
                0 => Google_Service_AnalyticsReporting_DateRangeValues {#606 ▼
                  #collection_key: "values"
                  #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
                  #pivotValueRegionsDataType: "array"
                  +values: array:2 [▼
                    0 => "1"
                    1 => "1"
                  ]
                  #internal_gapi_mappings: []
                  #modelData: []
                  #processed: []
                }
              ]
            }
            8 => Google_Service_AnalyticsReporting_ReportRow {#605 ▼
              #collection_key: "metrics"
              +dimensions: array:1 [▼
                0 => "18"
              ]
              #metricsType: "Google_Service_AnalyticsReporting_DateRangeValues"
              #metricsDataType: "array"
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
              +"metrics": array:1 [▼
                0 => Google_Service_AnalyticsReporting_DateRangeValues {#604 ▼
                  #collection_key: "values"
                  #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
                  #pivotValueRegionsDataType: "array"
                  +values: array:2 [▼
                    0 => "1"
                    1 => "1"
                  ]
                  #internal_gapi_mappings: []
                  #modelData: []
                  #processed: []
                }
              ]
            }
            9 => Google_Service_AnalyticsReporting_ReportRow {#603 ▼
              #collection_key: "metrics"
              +dimensions: array:1 [▼
                0 => "20"
              ]
              #metricsType: "Google_Service_AnalyticsReporting_DateRangeValues"
              #metricsDataType: "array"
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
              +"metrics": array:1 [▼
                0 => Google_Service_AnalyticsReporting_DateRangeValues {#569 ▼
                  #collection_key: "values"
                  #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
                  #pivotValueRegionsDataType: "array"
                  +values: array:2 [▼
                    0 => "1"
                    1 => "1"
                  ]
                  #internal_gapi_mappings: []
                  #modelData: []
                  #processed: []
                }
              ]
            }
            10 => Google_Service_AnalyticsReporting_ReportRow {#577 ▼
              #collection_key: "metrics"
              +dimensions: array:1 [▼
                0 => "21"
              ]
              #metricsType: "Google_Service_AnalyticsReporting_DateRangeValues"
              #metricsDataType: "array"
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
              +"metrics": array:1 [▼
                0 => Google_Service_AnalyticsReporting_DateRangeValues {#559 ▼
                  #collection_key: "values"
                  #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
                  #pivotValueRegionsDataType: "array"
                  +values: array:2 [▼
                    0 => "1"
                    1 => "1"
                  ]
                  #internal_gapi_mappings: []
                  #modelData: []
                  #processed: []
                }
              ]
            }
            11 => Google_Service_AnalyticsReporting_ReportRow {#558 ▼
              #collection_key: "metrics"
              +dimensions: array:1 [▼
                0 => "22"
              ]
              #metricsType: "Google_Service_AnalyticsReporting_DateRangeValues"
              #metricsDataType: "array"
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
              +"metrics": array:1 [▼
                0 => Google_Service_AnalyticsReporting_DateRangeValues {#600 ▼
                  #collection_key: "values"
                  #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
                  #pivotValueRegionsDataType: "array"
                  +values: array:2 [▼
                    0 => "4"
                    1 => "3"
                  ]
                  #internal_gapi_mappings: []
                  #modelData: []
                  #processed: []
                }
              ]
            }
            12 => Google_Service_AnalyticsReporting_ReportRow {#553 ▼
              #collection_key: "metrics"
              +dimensions: array:1 [▼
                0 => "23"
              ]
              #metricsType: "Google_Service_AnalyticsReporting_DateRangeValues"
              #metricsDataType: "array"
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
              +"metrics": array:1 [▼
                0 => Google_Service_AnalyticsReporting_DateRangeValues {#570 ▼
                  #collection_key: "values"
                  #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
                  #pivotValueRegionsDataType: "array"
                  +values: array:2 [▼
                    0 => "5"
                    1 => "3"
                  ]
                  #internal_gapi_mappings: []
                  #modelData: []
                  #processed: []
                }
              ]
            }
          ]
          +"totals": array:1 [▼
            0 => Google_Service_AnalyticsReporting_DateRangeValues {#556 ▼
              #collection_key: "values"
              #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
              #pivotValueRegionsDataType: "array"
              +values: array:2 [▼
                0 => "25"
                1 => "20"
              ]
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
            }
          ]
          +"minimums": array:1 [▼
            0 => Google_Service_AnalyticsReporting_DateRangeValues {#529 ▼
              #collection_key: "values"
              #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
              #pivotValueRegionsDataType: "array"
              +values: array:2 [▼
                0 => "0"
                1 => "0"
              ]
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
            }
          ]
          +"maximums": array:1 [▼
            0 => Google_Service_AnalyticsReporting_DateRangeValues {#557 ▼
              #collection_key: "values"
              #pivotValueRegionsType: "Google_Service_AnalyticsReporting_PivotValueRegion"
              #pivotValueRegionsDataType: "array"
              +values: array:2 [▼
                0 => "5"
                1 => "3"
              ]
              #internal_gapi_mappings: []
              #modelData: []
              #processed: []
            }
          ]
        }
      }
    ]
  }
]

0 个答案:

没有答案