Google Analytics(分析)信息中心响应无效

时间:2018-10-04 10:03:32

标签: javascript google-analytics google-analytics-api google-javascript-api

我想创建一个Google Analytics(分析)信息中心,其中包含我网站上的多个视图,但是我遇到了问题。 我按照https://ga-dev-tools.appspot.com/embed-api/basic-dashboard/上的所有说明进行了第一次测试。

这是代码

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
</head>
<body>
<script>
    (function (w, d, s, g, js, fs) {
        g = w.gapi || (w.gapi = {}); g.analytics = { q: [], ready: function (f) { this.q.push(f); } };
        js = d.createElement(s); fs = d.getElementsByTagName(s)[0];
        js.src = 'https://apis.google.com/js/platform.js';
        fs.parentNode.insertBefore(js, fs); js.onload = function () { g.load('analytics'); };
    }(window, document, 'script'));
</script>

<div id="embed-api-auth-container"></div>
<div id="chart-container"></div>
<div id="view-selector-container"></div>

<script>

    gapi.analytics.ready(function () {

        /**
         * Authorize the user immediately if the user has already granted access.
         * If no access has been created, render an authorize button inside the
         * element with the ID "embed-api-auth-container".
         */
        gapi.analytics.auth.authorize({
            container: 'embed-api-auth-container',
            clientid: 'MYCLIENTID.apps.googleusercontent.com'
        });


        /**
         * Create a new ViewSelector instance to be rendered inside of an
         * element with the id "view-selector-container".
         */
        var viewSelector = new gapi.analytics.ViewSelector({
            container: 'view-selector-container'
        });

        // Render the view selector to the page.
        viewSelector.execute();


        /**
         * Create a new DataChart instance with the given query parameters
         * and Google chart options. It will be rendered inside an element
         * with the id "chart-container".
         */
        var dataChart = new gapi.analytics.googleCharts.DataChart({
            query: {
                metrics: 'ga:sessions',
                dimensions: 'ga:date',
                'start-date': '30daysAgo',
                'end-date': 'yesterday'
            },
            chart: {
                container: 'chart-container',
                type: 'LINE',
                options: {
                    width: '100%'
                }
            }
        });


        /**
         * Render the dataChart on the page whenever a new view is selected.
         */
        viewSelector.on('change', function (ids) {
            dataChart.set({ query: { ids: ids } }).execute();
        });

    });
</script>

</body>
</html>

来自文件https://accounts.google.com/o/oauth2/iframerpc?action=checkOrigin&origin=http%3A%2F%2Fecommerce.tredweb.com&client_id=MYCLIENTID.apps.googleusercontent.com的响应始终为{"valid":false},但是该项目中我的网站已经获得了Google开发者控制台上的原始授权。我不明白问题出在哪里。

1 个答案:

答案 0 :(得分:0)

确保您的出生地恰好是“ http://ecommerce.tredweb.com