Either you get the requirements from management to add Google Analytics code to track Ecommerce events or you have it, but need to migrate from analytics.js library (GAT) to global site tag (GST) Puppetry may help you to ensure all the events are being sent within the user flows according to the requirements. Including such tests in CI/CD pipeline makes sure that with any upcoming code changes the defined requirements are still met.
Besides Puppetry validates event payloads in accordance with Google specification. So asserting for Google Analytics tracking events will check if the API is used correctly.
By using page.assertGaTracking in Puppetry we can test the following Google Analytics methods:
Common
Page View
Event
Social Interaction
App / Screen
User Timings
Exceptions
Ecommerce plugin
Adding Item
Adding Transaction
Enhanced Ecommerce plugin
Product Impression
Product Click
Product Details View
Addition to Cart
Removal from Cart
Checkout Process (Payment)
Checkout Process Option
Transaction
Refund
Internal Promotions
Let's see it in practice. Imagine we have a web shop that sells T-shirts. When user clicks on Add to cart link we expect a corresponding event to be sent to Google Analytics.
Demo store
So the test case to trigger the described event can be following:
Test case example for adding products to the shopping cart
As you see the entire funnel is covered with the tests. If any Google Analytics API calls are missing or do not comply the requirements we are going to be warned in the test report: