Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

Working version with v2, needs cleaning #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This plugin helps you configure your WordPress website to use Optimizely, a dram

Optimizely is a dramatically easier way for you to improve your website through A/B testing. Create an experiment in minutes with our easy-to-use visual interface with absolutely no coding or engineering required. Convert your website visitors into customers and earn more revenue today!

This plugin helps you configure your WordPress website to use Optimizely. After setting up an account at Optimizely.com, you simply enter your Optimizely project code in the plugin's configuration page and you're ready to start improving your website using Optimizely. Built for testing headlines, this plugin allows you to, create new experiments, see your experiment results, launch winners and much more all without leaving Wordpress.
This plugin helps you configure your WordPress website to use Optimizely. After setting up an account at Optimizely.com, you simply enter your Optimizely project code in the plugin's configuration page and you're ready to start improving your website using Optimizely. Built for testing headlines, this plugin allows you to, create new experiments, see your experiment results, launch winners and much more all without leaving Wordpress.

You'll need an [Optimizely.com](http://www.optimizely.com) account to use it.

Expand All @@ -30,9 +30,12 @@ You're ready to start using Optimizely!
1. Create multiple headlines for each post
2. View your results and launch winners directly from the dashboard

= 4.0.0 =
* The plugin is now working with Optimizely X

= 3.7.5 =
* FIXED bug on edit post page that displayed unwanted tooltip
* UPDATED default conditional activation code to exclude users coming from other sites
* UPDATED default conditional activation code to exclude users coming from other sites

= 3.7.1 =
* FIXED bug on config.js around the conditional activation input
Expand All @@ -43,10 +46,10 @@ You're ready to start using Optimizely!
* Updated the links to go to app.optimizely.com

= 3.6.1 =
* fixed bug in edit.php that only happened on servers running lower than PHP 5.4
* fixed bug in edit.php that only happened on servers running lower than PHP 5.4

= 3.6.0 =
* prevented the creation of an experiment until the post is published. This is to prevent goals and URL targeting to be incorrect when a post title changes and URL truncating
* prevented the creation of an experiment until the post is published. This is to prevent goals and URL targeting to be incorrect when a post title changes and URL truncating
* updated the results page to use the new Optimizely statistics engine

= 3.5.2 =
Expand All @@ -68,7 +71,7 @@ You're ready to start using Optimizely!


= 3.1.0 =
* Added ability to add custom post types
* Added ability to add custom post types

= 3.0.0 =
* Making repository Open Source
Expand Down
12 changes: 10 additions & 2 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ function optimizely_admin_notices() {
?>
<div id="optimizely-warning" class="updated fade">
<p><strong><?php echo sprintf(
'%s <a href="https://app.optimizely.com/tokens" target="_blank">%s</a> %s <a href="admin.php?page=optimizely-config#tabs-2">%s</a>.',
'%s <a href="https://app.optimizely.com/tokens" target="_blank">%s</a> %s <a href="#tabs-2" onclick="%s">%s</a>.',
esc_html__( 'Optimizely is almost ready. You must first add your', 'optimizely' ),
esc_html__( 'API Token', 'optimizely' ),
esc_html__( 'in the', 'optimizely' ),
esc_html__( 'jQuery("[href=#tabs-2]").click()' ),
esc_html__( 'configuration tab', 'optimizely' )
);?></strong></p>
</div>
Expand Down Expand Up @@ -73,6 +74,7 @@ function optimizely_conf() {
$optimizely_post_types = array_map( 'sanitize_text_field', $_POST['optimizely_post_types'] );
$optimizely_visitor_count = str_replace( ',', '', sanitize_text_field( $_POST['optimizely_visitor_count'] ) );
$project_name = sanitize_text_field( stripcslashes( $_POST['project_name'] ) );
$platform = sanitize_text_field( stripcslashes( $_POST['platform'] ) );
$variation_template = sanitize_text_field( stripcslashes( $_POST['variation_template' ] ) );
$activation_mode = sanitize_text_field( $_POST['optimizely_activation_mode' ] );
$conditional_activation_code = sanitize_text_field( stripcslashes( $_POST['conditional_activation_code' ] ) );
Expand Down Expand Up @@ -120,6 +122,12 @@ function optimizely_conf() {
update_option( 'optimizely_variation_template', $variation_template );
}

if ( empty( $platform ) ) {
update_option( 'optimizely_platform', OPTIMIZELY_DEFAULT_PLATFORM );
} else {
update_option( 'optimizely_platform', $platform );
}

if ( empty( $conditional_activation_code ) ) {
update_option( 'optimizely_conditional_activation_code', OPTIMIZELY_DEFAULT_CONDITIONAL_TEMPLATE );
} else {
Expand Down Expand Up @@ -151,4 +159,4 @@ function optimizely_conf() {

// Display the config form.
include( dirname( __FILE__ ) . '/config.php' );
}
}
108 changes: 85 additions & 23 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,62 @@
(function( $ ) {
window.swaggerPromise = new SwaggerClient({
url: "https://api.optimizely.com/v2/swagger.json",
usePromise: true
});


var classicProjectFetch = function(){


optly = new OptimizelyAPI( $( '#token' ).val() );

optly.get( 'projects', function( response ) {
$( '#project_id' ).empty();
$.each( response, function( key, val ) {
$option = $( '<option>' )
.val( val.id )
.text( val.project_name );

$( '#project_id' ).append( $option );
});

// Update project code w/ the default value
$( '#project_id' ).change();
});
};

var xProjectFetch = function(){
var token = $( '#token' ).val();
var authentication = {
clientAuthorizations: {
token: new SwaggerClient.ApiKeyAuthorization('Token', token, 'header'),
}
};

window.swaggerPromise.then(function(client){
return client.Projects.list_projects( {responseContentType: 'application/json'}, authentication);
}).then( function(result){
$( '#project_id' ).empty();
for( var i in result.obj ){
var project = result.obj[i];
$option = $( '<option>' )
.val( project.id )
.text( project.name );

$( '#project_id' ).append( $option );
}
$( '#project_id' ).change();
});


};

// Javascript for plugin settings page
function optimizelyConfigPage() {

/*
AUTHENTICATION W/ OPTIMIZELY
When the user presses the button, we call the GET projects/ endpoint to list out all the projects in their account.
When the user presses the button, we call the GET projects/ endpoint to list out all the projects in their account.
For each project, we show its name in the dropdown and store its ID in the value attribute for submission to a form.
*/

Expand All @@ -15,48 +66,59 @@
$( '#project_id' ).html( '' );
$( '#project_id' ).append( $loading );

optly = new OptimizelyAPI( $( '#token' ).val() );

optly.get( 'projects', function( response ) {
$( '#project_id' ).empty();
$.each( response, function( key, val ) {
$option = $( '<option>' )
.val( val.id )
.text( val.project_name );

$( '#project_id' ).append( $option );
});

// Update project code w/ the default value
$( '#project_id' ).change();
});

var value = $( '#platform' ).find( 'option:selected' ).attr( 'value' );
if( value === 'optimizely_x' ){
xProjectFetch();
} else {
classicProjectFetch();
}
/*
CHOOSING A PROJECT
When the user selects a project from the dropdown,
When the user selects a project from the dropdown,
we populate the project code box with the Optimizely snippet for that project ID.
*/
$( '#project_id' ).change(function() {
var id = $( '#project_id' ).val();
var name = $( '#project_id option:selected' ).text();

// For display purposes only!
var project_code = '<script src="//cdn.optimizely.com/js/' + parseInt( id ) + '.js"></script>';

$( '#project_code' ).text( project_code );
$( '#project_name' ).val( name );
});
});


}

$( document ).ready(function() {
$( '#optimizely-tabs' ).tabs();
$( document ).tooltip({
track: true
});


$('#platform').change(function(){
var value = $( this ).find( 'option:selected' ).attr( 'value' );
var activation_text = $( '#conditional_activation_code' ).text();
var variation_text = $( '#variation_template' ).text();
if( value === 'optimizely_x' ){
if( activation_text === OPTIMIZELY_DEFAULT_CONDITIONAL_TEMPLATE ){
$( '#conditional_activation_code' ).text( OPTIMIZELY_X_DEFAULT_CONDITIONAL_TEMPLATE );
}
if( variation_text === OPTIMIZELY_DEFAULT_VARIATION_TEMPLATE ){
$( '#variation_template' ).text( OPTIMIZELY_X_DEFAULT_VARIATION_TEMPLATE );
}
} else {
if( activation_text === OPTIMIZELY_X_DEFAULT_CONDITIONAL_TEMPLATE ){
$('#conditional_activation_code' ).text( OPTIMIZELY_DEFAULT_CONDITIONAL_TEMPLATE );
}
if( variation_text === OPTIMIZELY_X_DEFAULT_VARIATION_TEMPLATE ){
$( '#variation_template' ).text( OPTIMIZELY_DEFAULT_VARIATION_TEMPLATE );
}
}
});

optimizelyConfigPage();

$( 'input[name="optimizely_activation_mode"]' ).click(function(){
Expand Down
Loading