通过 Google Analytics API 获取属性的基本 URL?
我正在使用 Google Analytics API,并成功从中提取了大量数据。帐户 Feed (https://www.google.com/analytics/feeds/accounts/default
) 返回与您有权使用的帐户关联的网络媒体资源列表,格式如下 (大多数实际值被替换,不确定其中的敏感程度):
<entry gd:etag="W/"<charsblahblahblah>."" gd:kind="analytics#account">
<id>http://www.google.com/analytics/feeds/accounts/ga:########</id>
<updated>2011-08-04T12:01:33.467-07:00</updated>
<title>www.afifthofnothing.com</title>
<link rel="alternate" type="text/html" href="http://www.google.com/analytics"/>
<dxp:property name="ga:accountId" value="#####"/>
<dxp:property name="ga:accountName" value="My Sites"/>
<dxp:property name="ga:profileId" value="######"/>
<dxp:property name="ga:webPropertyId" value="UA-#####-#"/>
<dxp:property name="ga:currency" value="USD"/>
<dxp:property name="ga:timezone" value="America/Los_Angeles"/>
<dxp:tableId>ga:#######</dxp:tableId>
</entry>
我之前一直使用
我浏览了 Analytics API 文档,并用 Google 搜索、搜索所以,但没有看到任何方法可以从 Google Analytics 获取网络属性的基本 URL。我尝试通过 OAuth Playground 查询 id
字段以了解更多信息信息,它只会给我更多的错误,说最后一部分必须是 /default
。
有没有办法从数据 API 获取用户属性的基本 URL?看起来这将是非常基本的事情。如果没有,我将不得不尝试标题,如果它不是类似 URL 的,只需让用户自己输入它,这对用户不太友好,但这是我目前唯一能想到的。
I'm working with the Google Analytics API, and am pulling a lot of data from it successfully. The accounts feed (https://www.google.com/analytics/feeds/accounts/default
) returns a list of web properties connected to the account you're authorized for, in the following format (most actual values replaced, not sure how sensitive any of it is):
<entry gd:etag="W/"<charsblahblahblah>."" gd:kind="analytics#account">
<id>http://www.google.com/analytics/feeds/accounts/ga:########</id>
<updated>2011-08-04T12:01:33.467-07:00</updated>
<title>www.afifthofnothing.com</title>
<link rel="alternate" type="text/html" href="http://www.google.com/analytics"/>
<dxp:property name="ga:accountId" value="#####"/>
<dxp:property name="ga:accountName" value="My Sites"/>
<dxp:property name="ga:profileId" value="######"/>
<dxp:property name="ga:webPropertyId" value="UA-#####-#"/>
<dxp:property name="ga:currency" value="USD"/>
<dxp:property name="ga:timezone" value="America/Los_Angeles"/>
<dxp:tableId>ga:#######</dxp:tableId>
</entry>
I've previously been using the <title>
element as the base URL for the property, which usually works because that's the default title that Google Analytics assigns to the property. But if a user edits this (I'm querying my end-users' accounts, so I don't have control there) to something like "A Fifth Of Nothing", then the Analytics API will dutifully return that as the title, leaving me with no way to find the base URL.
I've scoured the Analytics API documentation and googled around, searched SO, but don't see any way to get the base URL of a web property from Google Analytics. I've tried querying the id
field via the OAuth Playground for more info, and it just gives me more errors, saying the last part has to be /default
.
Is there a way to get the base URL for a user's properties from the data API? It seems like this would be something pretty basic. If not, I'll have to resort to trying the title, and if it's not URL-like just have the user enter it themselves, which is not very user-friendly, but is the only thing I can come up with at this point.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用的策略是针对 ga:hostname 维度执行 ga:visits 查询并按降序排序。您通常可以使用它来显示主机/基本 URL。
我不认为“基本网址”有这样的属性,因为从技术上讲,您可以将谷歌跟踪代码放在多个网站上。在这种情况下,您将有多个基本网址。
The strategy to use is to do a query against the ga:hostname dimension for ga:visits and sort descending. You typically can use this to reveal the host/base url.
I don't think there is such a property for the "base url" because technically you can put the google tracking code on multiple websites. And in this instance you would have multiple base url.