PHP code example of widerfunnel / optimizely-x-sdk
1. Go to this page and download the library: Download widerfunnel/optimizely-x-sdk 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/ */
widerfunnel / optimizely-x-sdk example snippets
$optimizely = Optimizely::create($token);
$optimizely = Optimizely::create($token, true);
$optimizely->projects()->all();
$optimizely->projects()->find($projectId);
$optimizely->projects()->create([
'name' => 'My new project'
]);
$optimizely->project($projectId)->update([
'name' => 'My new name'
]);
$optimizely->project($projectId)->activate();
$optimizely->project($projectId)->archive();
$optimizely->project($projectId)->campaigns()->all();
$optimizely->campaign($campaignId)->find();
$optimizely->project($projectId)->campaigns()->create(
'Landing Page Optimization',
["status" => "not_started"]
);
$optimizely->campaign($campaignId)->update([
'name' => 'this is my new campaign'
]);
$optimizely->project($projectId)->experiments()->all([
'per_page' => <integer>,
'page' => <integer>,
'
$optimizely->experiment($experimentId)->find();
$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']
]);
$optimizely->experiment($experimentId)->update(['name' => 'newsite.com']);
$optimizely->experiment($experimentId)->delete();
$optimizely->experiment($experimentId)->archive();
$optimizely->experiment($experimentId)->variations()->update([
[
"name" => "control",
"weight" => 2500
],
[
"name" => "varA",
"weight" => 2500
],
[
"name" => "varB",
"weight" => 2500
],
[
"name" => "varF",
"weight" => 2500
]
]);
$optimizely->project($projectId)->audiences()->all();
$optimizely->audience($audienceId)->find();
$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']
);
$optimizely->audience($audienceId)->update([
'name' => 'My new name'
]);
$optimizely->project($projectId)->pages()->all();
$optimizely->page($pageId)->find();
$optimizely->project($projectId)->pages()->create($name, $edit_url, [
'category' => 'article'
]);
$optimizely->page($pageId)->update(['name' => 'my updated name']);
$optimizely->page($pageId)->delete();
$optimizely->project($projectId)->events()->all();
$optimizely->event($eventId)->find();
$optimizely->page($pageId)->events()->create(
'my sign up goal',
'click',
['selector' => '.sign-up-btn'],
['category' => 'sign_up']
);
$optimizely->page($pageId)->event($inPageEventId)->update([
'name' => 'my new page event name'
]);
$optimizely->page($pageId)->event($inPageEventId)->delete();
$optimizely->project($projectId)->events()->create([
'event_type' => 'custom',
'name' => 'my custom event',
'key' => 'my_event_key'
]);
$optimizely->project($projectId)->event($customEventId)->update([
'name' => 'my new custom event name'
]);
$optimizely->project($projectId)->event($customEventId)->delete();
$optimizely->project($projectId)->attributes()->all();
$optimizely->attribute($attributeId)->find());
$optimizely->project($projectId)->attributes()->create(
'my new attribute',
'my_new_attribute',
['description' => 'this is an attribute']
);
$optimizely->attribute($attributeId)->update(['name' => 'this is my updated attribute']);
$optimizely->attribute($attributeId)->delete());
$optimizely->experiment($experimentId)->results();
$optimizely->campaign($campaignId)->results();