Just fill out this form and wait some time: https://docs.google.com/forms/d/1qfRFysCikpgCMGqgF3yXdUyQW4xAlLyjKuOoOEFN2Uw/viewform
Google gives some help on that: https://developers.google.com/console/help/#service_accounts
Add a property for your test-domain, authorize your service Account with "Read & Analyze" permissions.
Add a dependency to
"phbergsmann/behat-google-analytics-extension": "*"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: 123456789In 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)
{
$this->getSubcontext('test')->visit($page);
}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:
@GoogleAnalyticsIdentifyByCampaignGoogle Analytics tracks a pageview on "/the/url/i/want/to/be/tracked/"Google Analytics tracks an event with category "<<EVENT-CATEGORY>>", action "<<EVENT-ACTION>>" and label "<<EVENT-LABEL>>"