Skip to main content

ga-attribution-scrape

Scrapes attribution data from GA through JS Network in Python for CSV exports.

Notes
  • The program assumes separate conversions and does not currently try to sum conversions together from separate conversion IDs.
  • When dealing with GA goals, will pull all goals as separate requests.
  • Works on a Service Account for authentication.
  • Will fill in missing dates in Bigquery if they exist. For example if a date is to be configured on 2020-12-01 and the earliest date in bq is 2020-12-03 then a dates list is generated for all dates between the two.
How to run

First import the Scrape function:

from ga_attribution_scrape import Scrape

Then initialise ga_attribution_scrape with the Scrape() function which must contain a config dictionary, which can be found at https://github.com/lewisaustinbryan/ga-attribution-scrape/blob/main/empty_config.yaml

Scrape().Goals(congig)

config

Service Account

You have to create a service account in Google Cloud Platform that has Bigquery access and GA access if you want to use a goal as a kpi for attribution reports. Help on creating one can be found here. https://cloud.google.com/iam/docs/creating-managing-service-accounts Separate Service accounts can be created for GA and Bigquery

There are four main parts to the configuration:

GA

Here you need to include account ID, Property ID and view ID.

Bigquery

For including the dataset ID and Table ID to tell Bigquery where to put the attribution reports.

Backdate

If backdate is True then will just pull yesterdays data, otherwise it will loop through each day on the specified start_date and end_date

Unless you explicitly set GOOGLE_APPLICATION_CREDENTIALS in the environment (e.g. using os module), be aware that the program expects you to backdate first with service account, then when backdate is False it refreshes the service used. There is no other option but it makes it very easy to put into a Cloud/Gamma Function.

Request

This is where we copy the request from the JS network in Google analytics in the "Conversions -> Multi Channel Funnels -> Model Comparison Tool" report for the request url https://analytics.google.com/analytics/web/exportReport/, which will have various query parameters associated with it.

Copy everything from Request Headers and and Form Data, which is included in the empty_config.

Get Attribution Report and send to Bigquery

from from ga_attribution_scrape import Scrape
ga_attribution  = Scrape().Goals(config)
ga_attribution.to_bq()

Release files for ga-attribution-scrape 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ga-attribution-scrape 0.2.1
File Size Uploaded
ga-attribution-scrape-0.2.1.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ga-attribution-scrape 0.2.1
File Interpreter ABI Platform
ga_attribution_scrape-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.1 kB

Release files / ga-attribution-scrape-0.2.1.tar.gz

Download URL ga-attribution-scrape-0.2.1.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e2aafb63336a85d2363928cf225ae16822725ff4777caffc95182f0ba17b118b
BLAKE2b-256 checksum
How to use checksums
954a40080b6da1f4a79db81b2800cddd10a6170a112c70d58f8bb5d481a0acf7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.4

Release files / ga_attribution_scrape-0.2.1-py3-none-any.whl

Download URL ga_attribution_scrape-0.2.1-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f6f0c59c19cea1f006fe132d9b32715c72601748b3cc296e2774abc33cdcb4ea
BLAKE2b-256 checksum
How to use checksums
3e81f1f680f26edb7b7fc9231943d0b88ec6ca0f9f32dabbb1fb928a4a9c8e81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page