以Javascript方式从Google

以Javascript方式从Google

本文介绍了以Javascript方式从Google AnalyticsAPI获取综合浏览量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用JavaScript从Google Analytics API中提取数据。
我似乎无法获取任何东西,只能说它的基本内容,如浏览量。



我正在使用



这是我用来连接的代码到GA API:

 (function(i,s,o,g,r,a,m){i ['GoogleAnalyticsObject '] = r; i [r] = i [r] || function(){
(i [r] .q = i [r] .q || [])。push(arguments)},新的Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a,m)
})(window,document,'script','// www.google-analytics.com/analytics.js','ga');

ga('create','XXX','example.com');
ga('send','pageview');

那么现在如何获得综合浏览量呢?
我试过使用这段代码,但是它返回undefined:

$ $ $ $ $ $ $ $ $() = ga.getByName('t0');
alert(tracker.get('page'));
});


解决方案

Analytics.js是一个跟踪API。它只是跟踪/发送数据到Google Analytics。



为了从Google Analytics检索数据,您需要使用不同的API。查找Reporting API。




I am having trouble with fetching data from Google Analytics API with javascript.I can't seem to fetch anything but lets say its something basic like pageviews.

I am using Analytics.js

This is the code i am using to connect to GA API:

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'XXX', 'example.com');
    ga('send', 'pageview');

So how do i get the pageviews now?I tried using this code but it returns undefined:

ga(function() {
      var tracker = ga.getByName('t0');
      alert(tracker.get('page'));
    });
解决方案

Analytics.js is a tracking API. It just tracks/sends data to Google Analytics.

In order to retrieve data from Google Analytics you need to use a different API. Look for the Reporting API.

https://developers.google.com/analytics/devguides/reporting/

这篇关于以Javascript方式从Google AnalyticsAPI获取综合浏览量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 10:09