How can I generate a GA tracking code programmatic

2019-04-08 23:57发布

How to generate Google Analytics tracking code programmatic-ally?

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

2条回答
啃猪蹄的小仙女
2楼-- · 2019-04-09 00:10

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

查看更多
够拽才男人
3楼-- · 2019-04-09 00:15

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).

查看更多
登录 后发表回答