Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.
You will need Python 3.7+ installed.
Use pip:
pip install gaunit
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 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.
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
If you want to use RobotFramework, check GAUnit Library for Robot Framework
Full documentation is available here.
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 pageview
s, but also event
s 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.
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.
This project is licensed under the MIT License - see the LICENSE file for details.
GAUnit was inspired by WAUnit. We decided to create a new library compatible with Python 3 and easier to set up.
FAQs
Testing Google Analytics implementations within CI pipelines
We found that gaunit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.