Search code examples
google-analyticsgoogle-analytics-api

Google Analytics : How large queries can be handled that needs more number of dimension and metrics then standard limit?


Let's say i have a scenario where i need to (unfortunately) pass metrics and dimensions more than standard defined limits i.e. 10 metrics and 7 dimensions.

Is there any standard way defined?

For adding up metrics i can understand that can be done through keeping the same dimensions and hit the query more than once and combining only metrics columns with previous results. But is there any way we can optimise these things?

But for Dimensions? Is there any standard way to handle these scenario?


Solution

  • I've been dealing with this for a while. I haven't found a resource that lays out a standard, but through trial and error I have come up with some solutions. Here are my basic rules:

    • Each batch query has a limit of 7 dimensions, but you'll need unique identifiers to stitch the rows from each query together. For example, if you are using two identifiers, you'll be limited to 5 new dimensions per query
    • If there is any dimension that is undefined in the query, the rows with the undefined dimension will be not be returned. So if you have such dimensions, use separate queries
    • Some standard dimensions (e.g. ga:browserSize) are not always defined for each event, so again, separate them
    • Add each dimension to the batch query and get the number of rows. If the number of rows decreases you probably have a dimension that is undefined some of the time

    I have a complete solution in Python using GA Reporting API v4. I need to standardize the client configuration and get it out on GitHub.

    The loss of the rows with undefined dimensions is a terrible pain point for me. It seems like GA is running INNER JOIN instead of LEFT JOIN in SQL, and there is no option to switch to LEFT JOIN. The JS code that saves those dimensions must be rock solid or you can potentially lose those rows in your reporting. (Listening, Google Analytics team?)