PHPackages                             heyday/silverstripe-googlecontentexperiments - 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. heyday/silverstripe-googlecontentexperiments

ActiveSilverstripe-module

heyday/silverstripe-googlecontentexperiments
============================================

2.0.0(12y ago)442[2 PRs](https://github.com/heyday/silverstripe-googlecontentexperiments/pulls)PHPPHP &gt;=5.3.2

Since Aug 21Pushed 1y ago25 watchersCompare

[ Source](https://github.com/heyday/silverstripe-googlecontentexperiments)[ Packagist](https://packagist.org/packages/heyday/silverstripe-googlecontentexperiments)[ RSS](/packages/heyday-silverstripe-googlecontentexperiments/feed)WikiDiscussions master Synced 2mo ago

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

SilverStripe Google Content Experiments
=======================================

[](#silverstripe-google-content-experiments)

Integration with Google Content Experiments for SilverStripe. Allows for Experiment Data to be integrated with your application so that experiments can be served without the usage of the GCE javascript implementation. For more information please see [running a server-side experiment](https://developers.google.com/analytics/solutions/experiments-server-side).

License
-------

[](#license)

SilverStripe Google Content Experiments is released under the [MIT license](http://heyday.mit-license.org/)

Installation
------------

[](#installation)

```
If using SilverStripe version 2.4, please use the 1.0.0 tag

$ composer require silverstripe-googlecontentexperiments

```

How to use
----------

[](#how-to-use)

### Setup

[](#setup)

First you must set up the correct authentication details so that Google Content Experiments can retrieve data from your Google Analytics account.

To do this:

- Visit
- Sign in with the account you use to manage your analytics
- Create a new project for the website you wish to target
- Browse to 'Services' and enable the Analytics API
- Browse to 'API access' and click 'Create another client ID'
- Choose 'Service account'
- Download the private key and store it somewhere securely within your application directory

Once this is done, you will see the details for the service account. From here, you will need to copy the email address which was generated and add it to the analytics account you are targeting with 'Read &amp; Analyze' access only. This will allow the server connection to read your experiment data.

### Configuration

[](#configuration)

Once you have set up the account and downloaded the private key for your application we have to configure the service. This can be completed in your `_config.php` with the following. This code sets up the dependancy injection container which is used.

```
use Heyday\GoogleContentExperiments;

$container = GoogleContentExperiments\Container::getInstance();
$container['google_content_experiments.class'] = 'Heyday\GoogleContentExperiments\GoogleContentExperiments';
$container['google_content_experiments.config.project_id'] = 'PROJECT_ID';
$container['google_content_experiments.config.web_property_id'] = 'WEB_PROPERTY_ID';
$container['google_content_experiments.config.profile_id'] = 'PROFILE_ID';
$container['google_analytics_service'] = function ($c) {

    $client = new \GoogleApi\Client(
        array(
            'application_name' => 'APPLICATION_NAME',
            'oauth2_client_id' => 'CLIENT_ID',
            'use_objects' => true
        )
    );
    $client->setAssertionCredentials(
        new \GoogleApi\Auth\AssertionCredentials(
                'EMAIL_ADDRESS',
                array('https://www.googleapis.com/auth/analytics.readonly'), // SCOPE
                file_get_contents(
                    BASE_PATH . PATH_TO_SERVER_KEY
                )
        )
    );

    return new \GoogleApi\Contrib\AnalyticsService(
        $client
    );

};
```

Generally the following applies:

```
PROJECT_ID: available from your Analytics account
WEB_PROPERTY_ID: available from your Analytics account - usually takes the form 'UA-11111111-11'
PROFILE_ID: available from your Analytics account
APPLICATION_NAME: the name of your Application
CLIENT_ID: available from the Google APIs console
SCOPE: Scope needed for the application - usually only 'https://www.googleapis.com/auth/analytics.readonly'
EMAIL_ADDRESS: the email address which we previously added to our Analytics account

```

You also need to include the GoogleContentExperimentScripts somewhere on the page(s) you want to test.

```

```

Its also a wise move to set up a cron job which will run the processor periodically for you and pick up the new experiments so that you can then run them. This also will update variations status as the experiments progress.

```
0 */12 * * * /path/to/webroot/sapphire/sake GoogleContentExperimentsProcessor
```

### Usage in templates

[](#usage-in-templates)

Templates are set up so that you can push the code without having to worry about the experiment being set up or running. This means that there is a necessary `` to make sure that when experiments finish the page goes back to 'normal' until it can be updated to the winning solution.

```

        THIS IS THE ORIGINAL VARIATION

        THIS IS ALTERNATIVE VARIATION

       THIS IS ALTERNATIVE VARIATION

    NO EXPERIMENT IS RUNNING RETURN TO REGULAR SERVICES

```

`GoogleContentExperimentVariation()` takes two parameters, which are separated by an underscore. The first is the VariationID we are checking for, the second is the ExperimentID (internal ID). The above example shows three variation possibilities for ExperimentID 1.

If you are only running one experiment per page, the ExperimentID is not needed, e.g. ``

Contributing
------------

[](#contributing)

### Unit Testing

[](#unit-testing)

```
$ composer install --prefer-dist --dev
$ phpunit

```

### Code guidelines

[](#code-guidelines)

This project follows the standards defined in:

- [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md)
- [PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md)
- [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~0 days

Total

2

Last Release

4644d ago

Major Versions

1.0.0 → 2.0.02013-08-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/de4d8d61f202a03e88c3ed30cce3bfedbc6f56a16e3f3b25546c61aadc51bca2?d=identicon)[heyday](/maintainers/heyday)

---

Top Contributors

[![camspiers](https://avatars.githubusercontent.com/u/51294?v=4)](https://github.com/camspiers "camspiers (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/heyday-silverstripe-googlecontentexperiments/health.svg)

```
[![Health](https://phpackages.com/badges/heyday-silverstripe-googlecontentexperiments/health.svg)](https://phpackages.com/packages/heyday-silverstripe-googlecontentexperiments)
```

###  Alternatives

[elgg/elgg

Elgg is an award-winning social networking engine, delivering the building blocks that enable businesses, schools, universities and associations to create their own fully-featured social networks and applications.

1.7k15.7k4](/packages/elgg-elgg)[aaemnnosttv/wp-sqlite-db

SQLite drop-in database driver for WordPress

58563.4k5](/packages/aaemnnosttv-wp-sqlite-db)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[johnbillion/user-switching

Instant switching between user accounts in WordPress and WooCommerce.

19768.3k2](/packages/johnbillion-user-switching)[rainlab/blog-plugin

Blog plugin for October CMS

17257.7k](/packages/rainlab-blog-plugin)[starcitizentools/citizen-skin

A beautiful, usable, responsive MediaWiki skin with in-depth extension support. Originally developed for the Star Citizen Wiki.

3164.5k](/packages/starcitizentools-citizen-skin)

PHPackages © 2026

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