Javascript 如何使用Google嵌入API获取选定的帐户ID和属性ID
我试图使用GoogleAPI for PHP从GA中提取一些数据,包括用户选择的货币类型 我有可用的PHP代码(独立),但为了提取用户选择的货币数据,我需要提取用户的Javascript 如何使用Google嵌入API获取选定的帐户ID和属性ID,javascript,php,google-analytics,google-analytics-api,Javascript,Php,Google Analytics,Google Analytics Api,我试图使用GoogleAPI for PHP从GA中提取一些数据,包括用户选择的货币类型 我有可用的PHP代码(独立),但为了提取用户选择的货币数据,我需要提取用户的Google\u Service\u Analytics\u Profile,我总共需要3个ID来获取该配置文件:$accountId,$webPropertyId,$profileId 下面是我提取数据的PHP代码: // Create a connection to the GA API service $ana
Google\u Service\u Analytics\u Profile
,我总共需要3个ID来获取该配置文件:$accountId
,$webPropertyId
,$profileId
下面是我提取数据的PHP代码:
// Create a connection to the GA API service
$analytics = new Google_Service_Analytics($client);
// Select the GA profile using the provided IDs
$ga_profile = $analytics->management_profiles->get($input_data->account_id, $input_data->property_id, $input_data->profile_id);
可以看出,Google\u Service\u Analytics\u ManagementProfiles\u Resource::get()
方法需要上述三个ID
我想使用嵌入API向用户显示一个选择器,允许他们选择我显示数据的概要文件,我打算将所选ID发布到我的PHP代码中,PHP代码从GA中提取数据并对其进行处理
不幸的是,嵌入API返回的唯一ID似乎是“视图ID”,我理解它是上面的$profileID
,但我不知道如何找到剩余的$accountId
和$webPropertyId
ID,以便通过PHP API提取“分析概要文件”
如何获取剩余的ID
这是我的HTML和JS:我能够使用以下Javascript从Google Embed API
ViewSelector
中获取剩余ID,用于更改
事件:
viewSelector.on('change', function() {
ids = {}
ids['account_id'] = viewSelector.B.fb;
ids['property_id'] = viewSelector.HC.fb;
ids['profile_id'] = viewSelector.RF.fb;
// Do something with `ids` object here...
});
更新的JS bin:尝试帐户摘要报告一个请求提供用户可以访问的所有内容,但您必须扫描它们才能找到您要查找的内容。我不明白您希望如何将嵌入API与PHP一起使用(根据谷歌的定义,嵌入API是一个Javascript库,加上嵌入API的视图选择器返回帐户-属性和视图ID)。在这方面,你能把你的问题说得更清楚一点吗?@Eikepierstorf我补充了一点关于我打算如何从嵌入(Javascript)中传输ID的解释服务器上PHP API的API。@DaImTo您建议的问题是,我无法可靠地知道Google Embed API
viewSelector
@MasterRoot24中所选值的ID。我认为DalmTo建议在PHP中使用管理API,而不是尝试混合技术,并尝试从JS Embed API获取数据到PHP。