Script to export all the Google Analytics Filters and its configuration in Google Spreadsheet

Practitioner - Awanish Dubey 30-Dec-2019

So, after learning how to export Google Analytics Goals & Google Analytics Custom Dimensions, let's learn how to export all the Google Analytics filters in one go using Google Appscript.

Types of Filters -

  • Exclude Filter
  • Include Filter
  • Uppercase Filter
  • Lowercase Filter
  • Search & Replace Filter
  • Advanced Filter

Here in this blog post, we will export all the filter types along with its details in 6 different sheets.

The output will be like this. A spreadsheet with 6 sheets for 6 different filter types.

Sheet 1 - Exclude Filter
Fields - 'Account Name', 'Account ID', 'Filter Id', 'Filter Name', 'Filter Field', 'Filter Match Type', 'Filter Expression Value', 'Case Sensitive'

Sheet 2 - Include Filter
Fields - 'Account Name', 'Account ID', 'Filter Id', 'Filter Name', 'Filter Field', 'Filter Match Type', 'Filter Expression Value', 'Case Sensitive'

Sheet 3 - Uppercase Filters
Fields - 'Account Name', 'Account ID', 'Filter Id', 'Filter Name', 'Filter Field'

Sheet 4 - Lowercase Filters
Fields - 'Account Name', 'Account ID', 'Filter Id', 'Filter Name', 'Filter Field'

Sheet 5 - Lowercase Filters
Fields - 'Account Name', 'Account ID', 'Filter Id', 'Filter Name', 'Filter Field', 'Search String', 'Replace String', 'Case Sensitive'

Sheet 4 - Event Goals
Fields - 'Account Name', 'Account ID', 'Filter Id', 'Filter Name', 'Field A', 'Extract A', 'Field B', 'Extract B', 'Output to Field', 'Output Constructor', 'Case Sensitive'

Hope you found it interesting & useful. To achieve this output, we will execute few lines of Appscript code. Best source to learn appscript is google developer’s site - https://developers.google.com/apps-script/overview.

Lets move to the basic requirement, basic setup and code creation section.

Basic requirement

  • You should have Gmail account with "Read and Analyze" 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 Google Analytics Filters".
  • In the header menu, select “Advanced Google Services” under the “Resources” section & enable both Google Analytics API & Spreadsheet API .

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 getGAfilters.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 “Google Analytics Filters – Date & Time” having six different sheets for different filter types.

This script will help you to export all the Google Analytics Filters and its details from all the avaiable GA accounts. You can modify this code to export filters from any specific GA account.

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.