PHP code example of heyday / silverstripe-googlecontentexperiments

1. Go to this page and download the library: Download heyday/silverstripe-googlecontentexperiments library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

heyday / silverstripe-googlecontentexperiments example snippets


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
    );

};