Google Analytics分析嵌入式API无法与Google Analytics分析Reporting APIv4配合使用

问题描述

我想将Google Analytics(分析)数据显示到我的客户站点,由于某种原因,Gapi无法识别报告api v4。有人可以帮我吗?

Home.components.ts

  constructor(
    private credentialService: CredentialsService,private router: Router,public gapiService: GoogleApiService
  ) {}

  ngOnInit() {
    this.gapiService.onLoad().subscribe( () => {
      const VIEW_ID = '216494010';

      function queryReports() {
        gapi.client.request({
          path: '/v4/reports:batchGet',root: 'https://analyticsreporting.googleapis.com/',method: 'POST',body: {
            reportRequests: [
              {
                viewId: VIEW_ID,dateranges: [
                  {
                    startDate: '7daysAgo',endDate: 'today'
                  }
                ],metrics: [
                  {
                    expression: 'ga:sessions'
                  }
                ]
              }
            ]
          }
        }).then(displayResults,console.error.bind(console));
      }

      function displayResults(response: any) {
        const formattedJson = JSON.stringify(response.result,null,2);
        // document.getElementById('query-output').value = formattedJson;
        console.log(response)
      }
    })
  }

Home.module.ts

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)