Skip to main content

Testing Google Analytics implementations within CI pipelines

Project description

GAUnit

Build Status Documentation Status

GAUnit is a Python library used for Google Analytics implementations testing.

It is designed to be used within your pipelines in various environments such as traditional websites or Single Page Applications.

GAUnit is compatible with GA4.

Features

  • Automate tests for Google Analytics implementations
  • Write tracking plans with Python dictionaries, JSON files or Google Sheets
  • Check HAR files against a tracking plan
  • Extract GA events from HAR files
  • Use Python or command line

Installation

You will need Python 3.7+ installed.

Use pip:

pip install gaunit

Usage

Let's say you have a new video player on your product page and you want to check that the right Google Analytics event is sent when the user clicks on "Play":

expected_events = [
    {
        "t": "pageview",
        "dp": "my_product_page_name"
    },
    {
        "t": "event",
        "ec": "Video",
        "ea": "Play"
    }
]

Run an automated test with Python

Run a selenium test case, export har and check it against your expected tracking plan:

import gaunit

# Run your Selenium test here and export har
# (see Documentation or examples for more details)
# ...

# create your tracking plan from dict, JSON files or Google Sheets
tracking_plan = gaunit.TrackingPlan.from_events("my_test_case", expected_events)
# check GA events
r = gaunit.check_har("my_test_case", tracking_plan, har_path="my_test_case.har")
print(r.was_successful())
# True
# Congrats! both events (pageview and click) were fired.

Or manually check HAR files with command line

Alternatively to automatic tests, you can manually browse your website, export a HAR file and check it through command line:

$ ga check test_case.har my_test_case  # passed
events in tracking plan: 3
--------------------------------------------------------------------------------
GA events found: total:4 / ok:3 / missing:0
✔ OK: all expected events found

$ ga check test_case.har my_test_case  # failed
events in tracking plan: 3
================================================================================
{'t': 'event', 'ec': 'Video', 'ea': 'Play'}
                                                                     ... missing
--------------------------------------------------------------------------------
GA events found: total:11 / ok:1 / missing:2
❌ FAILED: events missing

Robot Framework

If you want to use RobotFramework, check GAUnit Library for Robot Framework

Documentation

Getting Started.

Full documentation is available here.

Why GAUnit?

Testing your Google Analytics implementation is often time consuming and, let's say it, sometimes very boring!

But most of all, if your tracking is not reliable as your application evolves, your reportings won't be either. People in your company will loose confidence in your reportings when they have to take important business decisions. You will provide great reportings if you integrate tracking in your DevOps pipelines (and thus, in you Quality Assurance plan).

Some great tools let you automatically test your DataLayer, but sometimes it is not enough: you not only want to test pageviews, but also events like clicks and Ecommerce. You might want to test tracking in various environments like Single Page Application, AMP or Mobile Applications. GAUnit lets you do just that.

Contributing

GAUnit can be useful for several companies. Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Licence

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

GAUnit was inspired by WAUnit. We decided to create a new library compatible with Python 3 and easier to set up.

Roadmap

  • Mobile Apps
  • Tracking plan using analytics.js, GTM or GA4 API syntax
  • Dockerize (for simpler set up and CI/CD)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gaunit-0.5.6.tar.gz (14.1 kB view details)

Uploaded Source

File details

Details for the file gaunit-0.5.6.tar.gz.

File metadata

  • Download URL: gaunit-0.5.6.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.1

File hashes

Hashes for gaunit-0.5.6.tar.gz
Algorithm Hash digest
SHA256 9a0e6a9f6ddd7b7fab5aab5652aabf227df7cc808c0dfea0ddfa317e0b591cfa
MD5 32c70fe7d045a1e5a1a8731fb41eb951
BLAKE2b-256 1ff0a4c904a8522d244b47239419b7f18de741b06483b3a4d026f78c42bf31d9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page