Search code examples
google-analyticsgoogle-analytics-api

Google Analytics refresh token invalidates


We allow our users to connect their Google Analytics account to our CMS. However, many of them choose to have us manage their GA, so we have a lot of properties. Each property has its own View ID, and when we connect the View ID, we do so by entering the View ID. Then, the account select prompt shows up. We select the account that owns the property (which is usually the same account, say [email protected]), and then retrieve access and refresh token.

This all works well. Except, sometimes it seems the refresh token invalidates.

Is this because of the refresh token limit (we definitely manage more than 25 clients)? If so, what would be a better way to connect the property to the site, while still allowing users to use their own GA account if they wish to do so? I was thinking of trying to retrieve which google account is being use for the connect, but I am not sure how I would do that.

Any ideas?


Solution

  • I figured it out. The refresh token limit is per actual google account, took me a while to figure that out. I now store a default value in the main DB and if that one can access the ID that is to be connected, the default is used. Otherwise it will redirect to the Google auth window and authenticate normally.