widerfunnel / optimizely-x-sdk
Optimizely REST API SDK Wrapper
Installs: 5 611
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 12
Forks: 0
Open Issues: 1
Requires
- php: >=7.0
- guzzlehttp/guzzle: ^6.2
- tightenco/collect: ^5.3
Requires (Dev)
- nesbot/carbon: ^1.21
- phpunit/phpunit: ^5.5
- symfony/var-dumper: ^3.1
- vlucas/phpdotenv: ^2.4
This package is not auto-updated.
Last update: 2024-11-10 05:19:33 UTC
README
PHP Wrapper to interact with the Optimizely X API.
Installation
composer require widerfunnel/optimizely-x-sdk
Usage
Simply create an Optimizely object, with a valid OAuth Token in the constructor:
$optimizely = Optimizely::create($token);
If you wish to use the token based authentication, simply pass true
as a second argument:
$optimizely = Optimizely::create($token, true);
List projects
$optimizely->projects()->all();
Read a project
$optimizely->projects()->find($projectId);
Create a project
$optimizely->projects()->create([ 'name' => 'My new project' ]);
Update a project
$optimizely->project($projectId)->update([ 'name' => 'My new name' ]);
Delete a project
** Not supported by Optimizely X Rest API **
Activate a project (note: not functional, waiting on optimizely X api fix)
$optimizely->project($projectId)->activate();
Archive a project (note: not functional, waiting on optimizely X api fix)
$optimizely->project($projectId)->archive();
Campaigns
List Campaigns
$optimizely->project($projectId)->campaigns()->all();
Find Campaign
$optimizely->campaign($campaignId)->find();
Create Campaign
$optimizely->project($projectId)->campaigns()->create( 'Landing Page Optimization', ["status" => "not_started"] );
Update a Campaign
$optimizely->campaign($campaignId)->update([ 'name' => 'this is my new campaign' ]);
Experiments
List experiments in project
$optimizely->project($projectId)->experiments()->all([ 'per_page' => <integer>, 'page' => <integer>, 'include_classic' => <boolean> ] <optional>);
Find experiment
$optimizely->experiment($experimentId)->find();
Create an experiment
$optimizely->project($projectId)->experiments()->create( 'my test', [ [ "name" => "control", "weight" => 5000 ], [ "name" => "varA", "weight" => 5000 ] ], [ [ "aggregator" => "unique", "event_id" => 0, "field" => "revenue" ] ], ['status' => 'not started'] ]);
Update an experiment
$optimizely->experiment($experimentId)->update(['name' => 'newsite.com']);
Delete an experiment
$optimizely->experiment($experimentId)->delete();
Archive an experiment
$optimizely->experiment($experimentId)->archive();
Variations
Change Variations
$optimizely->experiment($experimentId)->variations()->update([ [ "name" => "control", "weight" => 2500 ], [ "name" => "varA", "weight" => 2500 ], [ "name" => "varB", "weight" => 2500 ], [ "name" => "varF", "weight" => 2500 ] ]);
Audiences
List audiences
$optimizely->project($projectId)->audiences()->all();
Find an audience
$optimizely->audience($audienceId)->find();
Create an audience
$optimizely->project($projectId)->audiences()->create( 'My second audience', '[\"and\", {\"type\": \"language\", \"value\": \"es\"}, {\"type\": \"location\", \"value\": \"US-CA-SANFRANCISCO\"}]', ["description" => 'People that speak spanish in San Fran'] );
Update an audience
$optimizely->audience($audienceId)->update([ 'name' => 'My new name' ]);
Delete an audience
** Not supported by Optimizely X Rest API **
Pages
List Pages
$optimizely->project($projectId)->pages()->all();
Find a Page
$optimizely->page($pageId)->find();
Create a page
$optimizely->project($projectId)->pages()->create($name, $edit_url, [ 'category' => 'article' ]);
Update a page
$optimizely->page($pageId)->update(['name' => 'my updated name']);
Delete a page
$optimizely->page($pageId)->delete();
Events
List Events
$optimizely->project($projectId)->events()->all();
Find Event
$optimizely->event($eventId)->find();
In Page Events
Create In-page Event
$optimizely->page($pageId)->events()->create( 'my sign up goal', 'click', ['selector' => '.sign-up-btn'], ['category' => 'sign_up'] );
Update In-Page Event
$optimizely->page($pageId)->event($inPageEventId)->update([ 'name' => 'my new page event name' ]);
Delete In-Page Event
$optimizely->page($pageId)->event($inPageEventId)->delete();
Custom Event
Create Custom Event
$optimizely->project($projectId)->events()->create([ 'event_type' => 'custom', 'name' => 'my custom event', 'key' => 'my_event_key' ]);
Update Custom Event
$optimizely->project($projectId)->event($customEventId)->update([ 'name' => 'my new custom event name' ]);
Delete Custom Event
$optimizely->project($projectId)->event($customEventId)->delete();
Attributes
List Attributes
$optimizely->project($projectId)->attributes()->all();
Find Attribute
$optimizely->attribute($attributeId)->find());
Create Attribute
$optimizely->project($projectId)->attributes()->create( 'my new attribute', 'my_new_attribute', ['description' => 'this is an attribute'] );
Update Attribute
$optimizely->attribute($attributeId)->update(['name' => 'this is my updated attribute']);
Delete Attribute
$optimizely->attribute($attributeId)->delete());
Results
Fetch the results of an experiment
$optimizely->experiment($experimentId)->results();
Fetch the results of an campaign
$optimizely->campaign($campaignId)->results();