=== Content Switcher === Contributors: Kleor Tags: analytics, cookie, content, env, get, google, multiple, number, optimizer, post, random, server, session, shortcode, switch, switcher, variable Requires at least: 2.5 Tested up to: 3.1 Stable tag: 1.7 Allows you to easily display a random number, a random or variable content on your website, and to optimize your website with Google Optimizer and Google Analytics. == Description == Content Switcher allows you to easily insert into posts, pages and widgets of your website random numbers, and random or variable contents. You can use it, for example, to display [COOKIE, ENV, GET, POST, SERVER or SESSION](http://www.php.net/manual/en/reserved.variables.php) variables. Content Switcher also allows you to optimize your website with Google Optimizer and to add the Google Analytics code to each page of your website. Complete Documentation: - [in English](http://www.kleor-editions.com/content-switcher/en) - [in French](http://www.kleor-editions.com/content-switcher) = Random Numbers = To display a random number between 0 and M, insert into your posts/pages/widgets a code like this: `[random-number max=M]` Example (random number between 0 and 5): `[random-number max=5]` To display a random number between m and M (m and M relative integers), insert into your posts/pages/widgets a code like this: `[random-number min=m max=M]` Example (random number between -3 and 8): `[random-number min=-3 max=8]` To display a random number belonging to a set, insert into your posts/pages/widgets a code like this: `[random-number set=a/b/c/...]` Example (random number belonging to { 34; 5; -3; 8; -21 }): `[random-number set=34/5/-3/8/-21]` You can use the "digits" attribute to display a random number with at least d digits: `[random-number min=m max=M digits=d]` Example (random number between 0 and 144, displayed with at least 3 digits): `[random-number max=144 digits=3]` Other example (random image taken from the short film Big Buck Bunny): `Random image taken from the short film Big Buck Bunny` = Random Contents = To display a random content, insert into your posts/pages/widgets a code like this: `[random-content] First random content[other] Second random content[other] Third random content[other] ... [/random-content]` Example: `[random-content] Somewhere over the rainbow, way up high[other] There's a land that I heard of, once in a lullaby[other] Somewhere over the rainbow, skies are blue[other] And the dreams that you dare to dream, really do come true [/random-content]` It's possible to display several times the same (random or not random) string of characters, using the "string" attribute. You can specify any string of characters for this attribute, including shortcodes, provided to replace "[" by "(" and "]" by ")". And don't forget to include the quotes at the beginning and the end of the string: `[random-content string="(random-content)First random string(other)Second random string(other)Third random string(other)...(/random-content)"] [string]...[string]...[string][/random-content]` The `[string]` shortcode displays the string of characters. Example (random image taken from the short film Big Buck Bunny): `[random-content string="(random-number min=1 max=30 digits=2)"] Random image taken from the short film Big Buck Bunny [/random-content]` = Variable Contents = To display a COOKIE, ENV, GET, POST, SERVER or SESSION variable, insert into your posts/pages/widgets a code like this: `[variable-string type=type name=name]` The "type" attribute can be equal to "cookie", "env", "get", "post", "server" or "session". Its default value is "get". The "name" attribute is the name of the variable. To display a variable content, insert into your posts/pages/widgets a code like this: `[variable-content] Default content[other] First alternate content[other] Second alternate content[other] ... [/variable-content]` The displayed content is not random but is determined by the URL of the page. Pages displaying the default content: http://permalink-of-the-page/ http://permalink-of-the-page/?content=0 Page displaying the first alternate content: http://permalink-of-the-page/?content=1 Page displaying the second alternate content: http://permalink-of-the-page/?content=2 This is the value of the "content" variable of the URL which determines the displayed content. If its value: - is equal to 0 or is not specified, then the displayed content is the default content - is equal to 1, then the displayed content is the first alternate content - is equal to 2, then the displayed content is the second alternate content - ... Example: `[variable-content] Somewhere over the rainbow, way up high[other] There's a land that I heard of, once in a lullaby[other] Somewhere over the rainbow, skies are blue[other] And the dreams that you dare to dream, really do come true [/variable-content]` Pages displaying the default content: http://permalink-of-the-page/ http://permalink-of-the-page/?content=0 Page displaying the first alternate content: http://permalink-of-the-page/?content=1 Page displaying the second alternate content: http://permalink-of-the-page/?content=2 Page displaying the third alternate content: http://permalink-of-the-page/?content=3 If you don't want to use a GET variable to display the variable content, you can also do the same thing with a [COOKIE, ENV, POST, SERVER or SESSION](http://www.php.net/manual/en/reserved.variables.php) variable using the "type" attribute. You can specify a name different than "content" for the variable using the "name" attribute: Example: `[variable-content name=lyric] Somewhere over the rainbow, way up high[other] There's a land that I heard of, once in a lullaby[other] Somewhere over the rainbow, skies are blue[other] And the dreams that you dare to dream, really do come true [/variable-content]` Pages displaying the default content: http://permalink-of-the-page/ http://permalink-of-the-page/?lyric=0 Page displaying the first alternate content: http://permalink-of-the-page/?lyric=1 Page displaying the second alternate content: http://permalink-of-the-page/?lyric=2 Page displaying the third alternate content: http://permalink-of-the-page/?lyric=3 You can specify values different than numbers for the variable using the "values" attribute. Example: `[variable-content name=lyric values=first/second/third/fourth] Somewhere over the rainbow, way up high[other] There's a land that I heard of, once in a lullaby[other] Somewhere over the rainbow, skies are blue[other] And the dreams that you dare to dream, really do come true [/variable-content]` Pages displaying the first lyric: http://permalink-of-the-page/ http://permalink-of-the-page/?lyric=first Page displaying the second lyric: http://permalink-of-the-page/?lyric=second Page displaying the third lyric: http://permalink-of-the-page/?lyric=third Page displaying the fourth lyric: http://permalink-of-the-page/?lyric=fourth You can display the value of the variable. To do this, simply use only the default content without specifying any alternate content. If the value of the variable is not specified in the URL, the default content will be displayed: `[variable-content name=name]Default content[/variable-content]` Example: `Welcome [variable-content name=first-name]to You[/variable-content]!` Page displaying your first name: http://permalink-of-the-page/?first-name=your-first-name = Google Optimizer = To use Google Optimizer, you must have an account. Sign up for one if you do not. Through the website of Google Optimizer, create a new experiment. A multivariate experiment allows you to test several items, but it also allows you to test only one item, as an A/B experiment. Click on "Multivariate Experiment". Check the "I've completed the steps above and I'm ready to start setting up my experiment" box and click on "Create". You will arrive on this page: New multivariate experiment - Step 1 Enter a name for your experiment, enter the address of your test page, the address of your conversion page, and click on "Continue". New multivariate experiment - Step 2 Select "You will install and validate the JavaScript tags", and click on "Continue". You will arrive on a page where you can get your control, tracking, and conversion scripts. You will find your tracking ID in your tracking script. It's a string of characters which starts with "UA": `var gwoTracker=_gat._getTracker("UA-XXXXXXXX-X");` Enter your tracking ID in the "Google Optimizer Account Tracking ID" field in the options page of Content Switcher, check the "Add JavaScript code" box and click on "Save Changes". If you have a Google Analytics account, you can do the same thing with the "Google Analytics Account Tracking ID" field. Your Google Analytics Account Tracking ID is mentioned on your Google Analytics dashboard. For your test page, create the "optimizer" (in lowercase letters) custom field and enter the string starting with "/" and ending with "/test" in your tracking script: `gwoTracker._trackPageview("/XXXXXXXXXX/test");` Insert into the content of your test page at least a code like this: `[optimizer-content name="Name of your content"] Your original content[/optimizer-content]` Don't forget to include the quotes at the beginning and the end of the name value: Example: `[optimizer-content name="Title"]

Content Switcher

[/optimizer-content]` For your conversion page, create the "optimizer" (in lowercase letters) custom field and enter the string starting with "/" and ending with "/goal" in your conversion script: `gwoTracker._trackPageview("/XXXXXXXXXX/goal");` When you have configured your tracking ID, your test page and your conversion page as shown above, click on "Validate pages". Google Optimizer will detect your control, tracking and conversion scripts. Click on "Continue". You will arrive on a page where you will can complete your experiment by creating your different variations. == Installation == 1. Unzip the plugin file. 2. Upload the "content-switcher" folder to the your plugins directory. 3. Activate the plugin through the "Plugins" menu in WordPress. 4. Configure the plugin through the Content Switcher options page in WordPress. == Frequently Asked Questions == = Why does Google Optimizer not work on my website? = Check the "Add JavaScript code" field in the options page of Content Switcher. Check also the "Google Optimizer Account Tracking ID" field in the same page. Check the "header.php" and "footer.php" files of your WordPress theme. Make sure that the first contains a call to "wp_head" and the second contains a call to "wp_footer". = How can I use shortcodes in my WordPress theme? = Insert into the PHP files of your theme a code like this: `` = How to use shortcodes in comments? = Edit the "functions.php" file (create it if it doesn't exist) of your WordPress theme and add this line of code: `add_filter('comment_text', 'do_shortcode');` == Screenshots == 1. Options Page == Changelog == * Version 1.7 * Improve the code * Version 1.6.2 * Update the Google Optimizer codes * Version 1.6.1 * Don't load any JavaScript file * Version 1.6 * Add the ability to use shortcodes in titles and excerpts * Version 1.5 * Add the ability to add the Google Analytics code to each page of your website * Best factorization of the code * Version 1.2.1 * Minify the code * Apply the "htmlspecialchars" function to GET and POST variables * Version 1.2 * Add [variable-string] shortcode * Add the ability to use and display COOKIE, ENV, GET, POST, SERVER and SESSION variables * Version 1.0 * Initial version