gpt4 book ai didi

google-analytics - 谷歌分析嵌入 API : Set selector display defaults

转载 作者:行者123 更新时间:2023-12-03 15:29:20 24 4
gpt4 key购买 nike

我正在使用 Google Analytics 嵌入 API。下面是我在 Google 的开发页面上使用的代码示例。有没有办法为选择器设置默认值?帐号 |属性(property) |看法

<!doctype html>
<html lang="en">
<head>
<title>Google Charts</title>
<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>

<script>
gapi.analytics.ready(function() {
var ACCESS_TOKEN = 'xxxxx'; // obtained from your service account

gapi.analytics.auth.authorize({
serverAuth: {
access_token: ACCESS_TOKEN
}
});


/**
* 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:users',
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>

</head>

<body>

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

</body>
</html>

最佳答案

您首先要找到您想要作为默认帐户的 ids 值。您只需通过控制台记录“ids”然后在 View 选择器容器中选择选择器来完成此操作。这将在您的浏览器控制台中超过一个数字。
然后您需要将 'ids' 的值设置为这个数字。您可以在两个地方更改此设置,首先将其添加到 dataChart 查询中。因此,例如,如果您的 ID 号是 12345678,那么您可以按如下所示编写它( ids: 'ga:12345678' ):

var dataChart = new gapi.analytics.googleCharts.DataChart({
query: {

ids: 'ga:12345678',

metrics: 'ga:users',
dimensions: 'ga:date',
'start-date': '30daysAgo',
'end-date': 'yesterday'
},
chart: {
container: 'chart-container',
type: 'LINE',
options: {
width: '100%'
}
}
});

然后,您还需要更改执行 dataChart 的 ids 值
viewSelector.on('change', function(ids) {
dataChart.set({query: {ids: ids}}).execute();
});

所以在查询中,第二个“id”被改变,如下所示:
viewSelector.on('change', function(ids) {
dataChart.set({query: {ids: 'ga:12345678'}}).execute();
});

关于google-analytics - 谷歌分析嵌入 API : Set selector display defaults,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27531279/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com