Script to export all the Google Analytics Goals & Funnels in Google Spreadsheet

Practitioner - Awanish Dubey 01-Oct-2019

Are you looking for any script which can download all the Google Analytics goals and its details in google spreadsheet? Then you are on the right site.

Just to refresh your knowledge, goals are of 5 types i.e.

  • Destination Goal
  • Duration Goal
  • Pages/Screens per session Goal
  • Event Goal
  • Smart Goal

Here in this blog, we will learn how to export Destination, Duration, Pages/Session & Event goals along with its details in the spreadsheet.

Example - Destination Goal Setup.

Before moving forward, can you recall that, have you ever created Google Analytics Solutions Design Document manually where you have listed down all the implemented goals with its types & details? Also, the funnels created under these goals, which can be up to 20 steps?

If yes, then you can definitely understand the pain of manually copying all the Goals into an excel sheet. It can take you hours to list down all the goals with its types, details & multiple steps funnel for all the views under multiple properties.

I believe you will never want to waste your time into this manual copy paste thing. So, what is the solution?

Quite simple – Few lines of Google Appscript code can help you to get all the goals along with the funnels

How will be the final output look like?

Here you go. A spreadsheet with four different sheets. Each sheet will have different goals type.

Sheet 1 - Destination Goals
Fields - account name', 'account id', 'property name', 'property id', 'view name', 'view id', 'goal type', 'goal id', 'goal name', 'goal value', 'goal active', 'goal created date', 'goal updated date', 'goal destination url', 'casesensitive', 'destination url match type', 'first step required', 'funnel-1-number', 'funnel-1-name', 'funnel-1-url', 'funnel-2-number', 'funnel-2-name', 'funnel-2-url', 'funnel-3-number', 'funnel-3-name', 'funnel-3-url', 'funnel-4-number', 'funnel-4-name', 'funnel-4-url', 'funnel-5-number', 'funnel-5-name', 'funnel-5-url'

Sheet 2 - Duration Goals
Fields - 'account name', 'account id', 'property name', 'property id', 'view name', 'view id', 'goal type', 'goal id', 'goal name', 'goal value', 'goal active', 'goal created date', 'goal updated date', 'duration type', 'duration value'

Sheet 3 - Pages/Screens per session Goals
Fields - 'account name', 'account id', 'property name', 'property id', 'view name', 'view id', 'goal type', 'goal id', 'goal name', 'goal value', 'goal active', 'goal created date', 'goal updated date', 'pages/screens per session - comparisontype', 'pages/screens per session - comparison value'

Sheet 4 - Event Goals
Fields - 'account name', 'account id', 'property name', 'property id', 'view name', 'view id', 'goal type', 'goal id', 'goal name', 'goal value', 'goal active', 'goal created date', 'goal updated date', 'event variable', 'event category match type', 'event category value', 'event variable', 'event action match type', 'event action value', 'event variable', 'event label match type', 'event label value', 'event condition type', 'event comparison type', 'event comparison value'

So, I believe, now we are quite clear that what we are going to achieve and how it will look like.

If this is something you are looking for, then let’s move to the next section – Basic Setup and Code creation

Basic requirement

  • You should have Gmail account with the admin access to your GA account.

Basic Setup

  • Login to your Gmail account and open https://script.google.com/home in a new tab.
  • Click on “New Script” to create new project. Once done, a project page will be opened in a new tab. Update the project name like "Export Goals".
  • In the header menu, select “Advanced Google Services” under the “Resources” section & enable both Google Analytics API & Spreadsheet API .

Basic Terminologies

  • GA Account known as account
  • GA Properties known as webProperties
  • GA Views known as profiles

Now write a code. In code.gs file, copy paste the below code & save the file (CTRL + S).

Once the file is saved, click the RUN option under header menu and select the function name getGAdata .Once the program starts executing/run, there will be a couple of access pop-up’s which needs to be “allowed”. You just need to click on “Allow” option.

Now, open https://docs.google.com/spreadsheets in a new tab. . You will get a spreadsheet with the name “Goals Data – Date & Time” having four different sheets for different goals type.

Note - There is a scope to make this code more optimized.

Please feel free to comment down or write us on connect@qaror.com , in case you need the code to be modified or optimized.