Package: gaunit
GAUnitGAUnit 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 withGA4.FeaturesAutomate tests for Google Analytics implementationsWrite tracking plans with Python dictionaries, JSON files or Google SheetsCheck HAR files against a tracking planExtract GA events from HAR filesUse Python or command lineInstallationYou will needPython 3.7+installed.Use pip:pipinstallgaunitUsageLet'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 PythonRun a selenium test case, export har and check it against your expectedtracking plan:importgaunit# 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 Sheetstracking_plan=gaunit.TrackingPlan.from_events("my_test_case",expected_events)# check GA eventsr=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 lineAlternatively to automatic tests, you can manually browse your website, export a
HAR file and check it through command line:$gachecktest_case.harmy_test_case# passedeventsintrackingplan:3--------------------------------------------------------------------------------
GAeventsfound:total:4/ok:3/missing:0
✔OK:allexpectedeventsfound

$gachecktest_case.harmy_test_case# failedeventsintrackingplan:3================================================================================{'t':'event','ec':'Video','ea':'Play'}...missing
--------------------------------------------------------------------------------
GAeventsfound:total:11/ok:1/missing:2
❌FAILED:eventsmissingRobot FrameworkIf you want to use RobotFramework, checkGAUnit Library for Robot FrameworkDocumentationGetting Started.Full documentation is availablehere.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 toolslet you automatically test your DataLayer, but sometimes it is not enough: you not only want to testpageviews, but alsoevents 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.ContributingGAUnit 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.LicenceThis project is licensed under the MIT License - see theLICENSEfile for details.AcknowledgmentsGAUnit was inspired byWAUnit. We decided to create a new library compatible with Python 3 and easier to set up.RoadmapMobile AppsTracking plan using analytics.js, GTM or GA4 API syntaxDockerize (for simpler set up and CI/CD)