PHPackages                             phbergsmann/behat-google-analytics-extension - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. phbergsmann/behat-google-analytics-extension

AbandonedArchivedLibrary[Testing &amp; Quality](/categories/testing)

phbergsmann/behat-google-analytics-extension
============================================

0.1.0(12y ago)4171MITPHP

Since Apr 21Pushed 12y ago1 watchersCompare

[ Source](https://github.com/phbergsmann/behat-google-analytics-extension)[ Packagist](https://packagist.org/packages/phbergsmann/behat-google-analytics-extension)[ RSS](/packages/phbergsmann-behat-google-analytics-extension/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (5)Versions (2)Used By (0)

Behat Google Analytics Extension
================================

[](#behat-google-analytics-extension)

Prerequisites
-------------

[](#prerequisites)

##### Google Analytics Realtime API beta access

[](#google-analytics-realtime-api-beta-access)

Just fill out this form and wait some time:

##### A Google API Service Account

[](#a-google-api-service-account)

Google gives some help on that: [https://developers.google.com/console/help/#service\_accounts](https://developers.google.com/console/help/#service_accounts)

##### A Google Analytics Account

[](#a-google-analytics-account)

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

Installation and configuration
------------------------------

[](#installation-and-configuration)

### via composer add the extension

[](#via-composer-add-the-extension)

Add a dependency to

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

### extend your behat.yml

[](#extend-your-behatyml)

```
default:
    extension:
        PhBergsmann\BehatGoogleAnalyticsExtension\Extension:
            service_account_name: 1234567890@developer.gserviceaccount.com
            key_file_location: /PATH/TO/YOUR/PRIVATE/KEY
            client_id: 1234567890.apps.googleusercontent.com
            view: 123456789
```

### Include the context-class

[](#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[^"]+)"$/
	* @Override When /^(?:|I )go to "(?P[^"]+)"$/
	*/
	public function visit($page)
	{
		$this->getSubcontext('test')->visit($page);
	}
```

Start testing
-------------

[](#start-testing)

#### Identifying the test-run

[](#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:

```
@GoogleAnalyticsIdentifyByCampaign
```

#### The extension adds the following step-definitions:

[](#the-extension-adds-the-following-step-definitions)

##### Check if the given URL has been tracked

[](#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

[](#check-if-the-given-event-was-triggered)

```
Google Analytics tracks an event with category "", action "" and label ""
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4405d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/21623fd9caf4366b99e23ee6daba91be804579727bb500db77e2b49a72603f3e?d=identicon)[phbergsmann](/maintainers/phbergsmann)

### Embed Badge

![Health badge](/badges/phbergsmann-behat-google-analytics-extension/health.svg)

```
[![Health](https://phpackages.com/badges/phbergsmann-behat-google-analytics-extension/health.svg)](https://phpackages.com/packages/phbergsmann-behat-google-analytics-extension)
```

###  Alternatives

[drupal/drupal-extension

Drupal extension for Behat

22215.1M147](/packages/drupal-drupal-extension)[drevops/behat-steps

Collection of steps for Behat

25381.7k3](/packages/drevops-behat-steps)[devinci/devinci-behat-extension

Provides extra behat goodies.

17593.9k](/packages/devinci-devinci-behat-extension)[genesis/behat-fail-aid

Get more out of your test suite by getting it to work with you when tests fail. Screenshots and more. Works with Goutte and MinkExtension.

281.5M17](/packages/genesis-behat-fail-aid)[polishsymfonycommunity/symfony2-mocker-extension

Behat extension for mocking services defined in the Symfony2 dependency injection container.

26253.1k4](/packages/polishsymfonycommunity-symfony2-mocker-extension)[elkan/behatformatter

This will create a formatter for Behat 3! Fast, Easy and Pretty!

1739.8k](/packages/elkan-behatformatter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
