如何使用Google Embed API获取所选的帐户ID和属性ID

时间:2015-03-26 11:48:23

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

我尝试使用Google API for PHP从GA中提取一些数据,包括用户选择的货币类型。

我有工作的PHP代码(孤立地),但是为了提取用户选择的货币数据,我需要提取用户Google_Service_Analytics_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);

可以看到from the sourceGoogle_Service_Analytics_ManagementProfiles_Resource::get()方法需要上面提到的三个ID。

我想使用Embed API向用户显示一个选择器,允许他们选择我显示数据的配置文件,并打算将选定的ID发布到我的PHP代码,该代码从GA中提取数据并对其进行处理。

不幸的是,似乎Embed API返回的唯一ID是"查看ID",我理解上面是$profileID,但我对如何丢失我找到剩余的$accountId$webPropertyId ID,以便我可以提取" Google Analytics配置文件"通过PHP API。

如何获取剩余的ID?

这是我的HTML和JS:http://jsbin.com/naxiyomeko/1/edit?html,js,console,output

1 个答案:

答案 0 :(得分:1)

我可以使用以下Javascript为ViewSelector事件从Google嵌入API change获取剩余的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:http://jsbin.com/hirapupayi/1/edit?html,js,console,output

相关问题