0.1.0 2014-04-21 13:29 UTC



Google Analytics Realtime API beta access

Just fill out this form and wait some time:

A Google API Service Account

Google gives some help on that:

A Google Analytics Account

Add a property for your test-domain, authorize your service Account with "Read & Analyze" permissions.

Installation and configuration

via composer add the extension

Add a dependency to

"phbergsmann/behat-google-analytics-extension": "*"

extend your behat.yml

            key_file_location: /PATH/TO/YOUR/PRIVATE/KEY
            view: 123456789

Include the context-class

In your custom feature-context add the new context in the constructor:

     * Initializes context.
     * Every scenario gets it's own context object.
     * @param array $parameters context parameters (set them up through behat.yml)
    public function __construct(array $parameters)
		  $this->useContext('googleanalytics', new PhBergsmann\BehatGoogleAnalyticsExtension\Behat\Context\GoogleAnalyticsContext());

If you want to use the campaign-identifier to allow concurrent testing (recommended) add these lines to your feature-context:

	* Opens specified page.
	* @Override Given /^(?:|I )am on "(?P<page>[^"]+)"$/
	* @Override When /^(?:|I )go to "(?P<page>[^"]+)"$/
	public function visit($page)

Start testing

Identifying the test-run

Google Analytics doesn't have the possibility to identify users (by giving them some retrievable ID). To bypass this limitation the extension adds the possibility to "tag" a testrun by injecting campaing-tracking parameters. Tests run perfectly fine without user-tagging but when you run the same test twice within 5 minutes there is no guarantee, that the second run does not deliver a false positive because the test was working in the first run. To enable campaing tagging add the following tag to your scenario:


The extension adds the following step-definitions:

Check if the given URL has been tracked
Google Analytics tracks a pageview on "/the/url/i/want/to/be/tracked/"
Check if the given event was triggered
Google Analytics tracks an event with category "<<EVENT-CATEGORY>>", action "<<EVENT-ACTION>>" and label "<<EVENT-LABEL>>"