lunes, marzo 15, 2021

List all custom dimensions and metrics of your Google Analytics properties using G Management API and Google Apps Script (GAS)

Well for once in many time, actually I think the first one I’m not gonna talk about GTM. This time I’m gonna dedicate this article to GAS, Google Apps Script. Some people will call it scripting other ones will say it can’t be considered as that, well readers, judge by yourselves and make an opinion in this overall view.

In this article I’m going to provide you a google spreadsheet where you can get a list of all your properties of Google Analytics and also extract all the custom dimensions and properties from a Google Analytics property.

The only thing that is required here is to have Google Analytics properties with custom dimensions or custom properties and google drive for creating a Google Spreadsheet.

I have created a customised menu where all the functions are allocated there. The menu es called “GA - Lists” and is loaded when you open the Google Spreadsheet.



For checking all the code behind the scenes, you only have to go to “Tools”. And the script editor.



It will open a new tab with all the code behind. I know I should have cleaned the code because it contains more lines that the ones we need for get a list of all our Google Analytics views, and the custom dimensions and properties of each property.

The reason behind is that I created before a script to iterate with all the properties and extract all CDs and CMs but in my company we have a bunch of properties and each of it contains another bunch of CDs and CMs. When I tried to run this script, it happened that I exceeded the time for it and I got a time out. For sure there’s someone outside there smarter than me (actually that’s not hard to find) and have another idea of how to retrieve them without a timeout error.

I have created a tab called README that is self-explanatory, explaining what every part of the menu does.



So first thing: List of views that you have access to Google Analytics (GA). Chop chop, click on “GA – Lists” --> “List Views” --> “List all Views”.

It will empty or replace the tab “ALL VIEWS” and will write down all the views you have access to GA.

You can check line 97 of the code in the function getGAViews().



If you want to know all the properties that you have access of GA, same old same old: “GA - Lists” --> “List Properties” --> List all Properties. You can find that part of the code in the line 121 in the function name getGAProperties().


Now it comes the tricky one, if you want to extract all the CDs and all the CMs of a GA property, you first you need to know the property ID “UA-123456-1”, this is why I created the “List all properties”. 

So, the only thing you need to do is copy the UA property ID and then when you run the menu it will prompt you for the property ID. Don’t panic this prompt is pretty and despite of my shitty English you will perfectly understand what I mean about.

Then “GA - Lists” --> “List CD & CM” --> “List all CD and CM for a property ID”


As you have already copied the property ID, for example “UA-123456-1”, when you got this popup, paste it on the text box and click OK


It will create a new tab with the name if the ID and all the custom dimensions and metrics under that property

More info in the code on line 223, function name ListCDAndCMPerProperty()

And now, the time you’ve been waiting for: here you can have view access to the document. Feel free to copy to your G Drive and don’t forget to mention how much you love damupi for making your life easier.

Live long and prosper. 






 

No hay comentarios:

Publicar un comentario

Los comentarios se mostrarán una vez aprobados