Puppetry
3.2.2
3.2.2
  • Welcome Puppetry
  • Getting Started
  • Project
  • Suite
  • Group
  • Target
    • Simple Target
    • iFrame Target
    • ShadowDOM Target
    • Chained Target
    • Shared Target
  • Test Case
  • Test Step / Action
    • Page Commands
    • Page Assertions
    • Target Commands
    • Target Assertions
  • Managing Records
  • Snippets
  • Running tests
    • Interactive Mode
    • Troubleshooting
  • Test Report
  • Export
    • Exporting as Jest Project (CI-friendly)
    • Exporting as Test Specification
  • Settings
  • Template Expressions
  • Testing Techniques
    • Testing Dynamic Content
    • Exhaustive Testing
    • Performance Testing
    • Visual Regression Testing
    • Testing Shadow DOM
    • Testing Google Analytics tracking code
    • Testing Chrome Extensions
    • Testing REST API
    • Mocking HTTP/S Requests
    • Testing Transactional Emails
      • Example with Restmail.net
      • Example with Mailinator
      • Example with IMAP bridge
      • Example with Google API
    • Testing Forms with Captcha
  • Version Control
  • Tips and Tricks
    • Embrace the Power of CSS
  • Command API
  • Test Application
Powered by GitBook
On this page

Was this helpful?

  1. Testing Techniques

Testing Google Analytics tracking code

PreviousTesting Shadow DOMNextTesting Chrome Extensions

Last updated 5 years ago

Was this helpful?

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 () to global site tag () 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.

So the test case to trigger the described event can be following:

When user follows the link he or she gets Shopping Cart popup where it's possible to click Checkout link to continue with the checkout process.

Next user gets Checkout popup to select the payment method and clicks Proceed link to continue.

This user behavior we turn into the test case:

Asserting for Checkout / checkout_progress omitted to simplify the example.

Eventually user confirms the purchase :

The case we also cover with tests:

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:

The assertion for may look like that:

Here we assert for the :

We also assert for the :

Here we assert for :

GAT
GST
the expected GST API call
Checkout / begin_checkout event
Checkout option event
purchase event
Demo store
Test case example for adding products to the shopping cart
Starting the checkout process
Checkout process step
Testing checkout progress
Asserting checkout progress event
Asserting checkout step event
Purchase popup
Testing purchase event
Asserting purchase
Assertion for Google Analytics event failed