This script is intended to clean up PII (personally identifiable information) related client data from Google Analytics.
It's quite a problem if you have to clean up multiple records manually, let's say if you have too many records to clean up, that will take days to finish the work, however with this script you can accomplish the task within a minutes.
- Read and get acquainted with the "Creating and managing service account keys" topic,
- Create a new service account (if there is no any),
- Give that service account Editor's permission,
- Enable Google Analytics's API,
- Export the service account json key file,
- Place
serviceAccountKey.json
inside of./src/config
folder of the project,
- Set Google Analytics' tracking id as environmental variable
TRACKING_ID
(you either have to define it from your OS or set it inside of.env
file), - Add in Google Analytics' "Admin" settings page's "Admin" tab's "View" subtab's "View User Management" section the
client_email
email address of the service account.
- In Google Analytics' create a new segmet of filtration where you'll define your own rules of filtration,
- In Google Analytics' "Audience" section's "User Explorer" subsection export the cliend id/user id list from Google Analytics as CSV file
exported_report.csv
.
- Place
exported_report.csv
inside of the root folder of the project, - Run
npm start
to initiate, - Wait until you'll get the confirmation that the job is done.