How can I generate a GA tracking code programmatically?

天大地大妈咪最大 提交于 2019-12-21 15:18:13

问题


How to generate Google Analytics tracking code programmatic-ally?

I am new to Google Analytics API, can someone please help


回答1:


It is NOT possible to create new Google Analytics accounts or profiles programmatically using the existing APIs.

There are two APIs available, the Data Export API and the Management API. However, they are bot read-only.

With the Google Analytics Data Export API, you can develop client applications to request data from an existing Analytics profile for an authorized user, and refine the results of the request using query parameters. Currently, the Data Export API supports read-only access to your Google Analytics data.

 

Currently, the Management API supports read-only access to five components of the Google Analytics Management system: Account data,Profile data, Web property data, Goal data, Advanced segments




回答2:


It's not currently possible to create Google Analytics accounts automatically at the moment but generating the tracking code is possible.

The only real variation between the tracking code generated each time you create a profile for a new domain is the web property ID. This is in the format UA-XXXXXXX-X. Each X is a number - the first 7 numbers are the account number and the number after the last dash relates to each web property set up for the account.

You can use the accounts feed of the API to get a list of accounts and their profiles. If an account only has one profile then it's possible to use the web property ID of it to automatically generate the tracking code. However, if there's multiple web properties then you would need a way to decide which one to use (present the user with a selection list etc).



来源:https://stackoverflow.com/questions/5455041/how-can-i-generate-a-ga-tracking-code-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!