Command Line¶
If you have HAR files, GAUnit commands will greatly help you to quickly see which Google Analytics events were fired, check if they correspond to what is expected, write a tracking plan from this base, etc.
GAUnit comes with 2 separate commands:
ga check: from HAR file and a test case name, check events against an existing tracking planga extract: from a HAR file, extract and print GA events, possibly to add them to a tracking plan
ga check¶
This command takes a test case name, a HAR file and a tracking plan
(in the form of a JSON file, tracking_plan.json by default)
and prints the result in the console. By default, it only prints missing events.
Arguments¶
$ ga check file.har test_case
file.harPath to HAR file you want to check
test_caseName/id of the test case in the tracking plan
Optional arguments¶
--tracking_plan,-tPath to tracking plan JSON file (
tracking_plan.jsonby default)--all,-aPrint all expected events from tracking plan (not only the missing ones)
--help,-hShow help on this command
Examples¶
Examples can be run from the GAUnit Getting started sample directory on Github.
Check a HAR file against a tracking plan:
$ ga check demo_store_add_to_cart.har demo_store_add_to_cart
events in tracking plan: 3
--------------------------------------------------------------------------------
GA events found: total:9 / ok:3 / missing:0
✔ OK: all expected events found
Specific path for the tracking plan:
$ ga check -t tracking_plan.json demo_store_add_to_cart.har demo_store_add_to_cart
events in tracking plan: 3
--------------------------------------------------------------------------------
GA events found: total:9 / ok:3 / missing:0
✔ OK: all expected events found
Print all events (not only the missing ones):
$ ga check --all demo_store_add_to_cart.har demo_store_add_to_cart
events in tracking plan: 3
================================================================================
{'t': 'pageview', 'dt': 'Home'}
... OK
================================================================================
{'t': 'pageview', 'dt': 'Product View'}
... OK
================================================================================
{'t': 'event',
'ec': 'ecommerce',
'ea': 'add_to_cart',
'ev': '44',
'pr1nm': 'Compton T-Shirt',
'pr1pr': '44.00'}
... OK
--------------------------------------------------------------------------------
GA events found: total:9 / ok:3 / missing:0
✔ OK: all expected events found
ga extract¶
This command takes a HAR file, extracts all Google Analytics events and prints them in the console (Python dict format). You can also filter events parameters.
Purposes of this command are :
extract events and use them as an input for future tracking plans
look for specific events and parameters after a browsing session
Optional arguments¶
--filter,-fList of events parameters you want to extract, separated by a comma (
--filter a,b,c). Other parameters are filtered out.--help,-hShow help on this command
Examples¶
Examples can be run from the GAUnit Getting started sample directory on Github.
Show all events found in a HAR file:
$ ga extract demo_store_add_to_cart.har
[{'_v': 'j87', 'a': '1597243964', 'dt': 'Home', 't': 'pageview', 'v': '1'},
{'_gid': '1844211766.1609794530',
'_s': '2',
'_u': 'aGBAAUALAAAAAC~',
'_v': 'j87',
'a': '2035613723',
...
Filter events. Only show event type and page title :
$ ga extract --filter t,dt,ea demo_store_add_to_cart.har
[{'dt': 'Home', 't': 'pageview'},
{'dt': 'Home', 'ea': 'view_item_list', 't': 'event'},
{'dt': 'Home', 'ea': 'view_promotion', 't': 'event'},
{'dt': 'Home', 'ea': 'select_content', 't': 'event'},
{'dt': 'Product View', 't': 'pageview'},
{'dt': 'Product View', 'ea': 'view_item', 't': 'event'},
{'dt': 'Product View', 'ea': 'view_promotion', 't': 'event'},
{'dt': 'Product View', 'ea': 'view_item_list', 't': 'event'},
{'dt': 'Product View', 'ea': 'add_to_cart', 't': 'event'}]