Website Optimizer: Embedding in Web Page
Embedding the Website Optimizer in a Web Page allows the Script to Insert the Variable Elements that are being optimized into the web page.
This tutorial applies to simple Web Pages and Sites. Not sites using Content Management Scripts. These will require plugins so that the Database can be shared.
Triggering the Script
The first thing that needs to be inserted is some code to trigger the Script. This will point to the multivar.php file.
In a PHP page you insert an Include Statement. For example, it may be added to the header.php file of your Template.
Example Include Statement:
include(’mv/multivar.php’);
Note that the path must lead to multivar.php from wherever the file that you are including the statement in resides.
Also, if the Include Statement is not in a block of PHP code, it needs to be surrounded by the start (<?php) and end (?>)tags for a PHP code block.
And of course, it has to be on a .php page (which could be inserted as an iframe on a non-php page).
Embedding the Code for Groups
To tell the Script what Group of Elements we are working with, the include Statement is immediately followed by a function call to group(’id’).
The id is the number of the Group you created in the Groups Admin Area.
Example code to trigger the script and inform it that we are optimizing the Website Elements of Group 1:
<?php
include(’mv/multivar.php’);
group(1);
?>
<p>Ready to start</p>
Embedding the Code for Elements
Now we need to insert a snippet of PHP code wherever we want an Element that we are optimizing to appear. We set up these Elements in the Elements Admin Area.
We simply call the function element(’id’); where id is the number of the Element. This function is contained in the multivar.php file that we included earlier.
Say Element 1 was the anchor text for an HTML link. We would insert it as follows:
<a href=”/”><?php element(1); ?></a>
And we repeat this process for any other Elements (using their particular ID numbers) that we have defined via the Admin Interface.
Now the script should insert the Element code into your Web Page when it is viewed in a Web Browser.
Possible issues:
If there is an existing function in your code called element() then please rename the function in either your code or inside the multivar.php file.
It’s possible that there may be a clash with your code that has already created a Database object. In this case, the database object may not be compatible with our code. By examining the code of our WordPress plugin, you can see how to use the Website Optimizer as an external resource rather than trying to combine it with your code.