<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-2825349447042335729</atom:id><lastBuildDate>Thu, 04 Mar 2010 15:21:22 +0000</lastBuildDate><title>Google Website Optimizer Tricks</title><description></description><link>http://www.gwotricks.com/test/default.htm</link><managingEditor>noreply@blogger.com (Eric Vasilik)</managingEditor><generator>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-2825349447042335729.post-2576513173817915303</guid><pubDate>Thu, 16 Jul 2009 06:17:00 +0000</pubDate><atom:updated>2009-07-19T22:21:42.986-07:00</atom:updated><title>Tracking Outbound Links -- The Right Way</title><description>&lt;p&gt;Let's say you want to run an experiment on a page in the &lt;b&gt;foo.com&lt;/b&gt; domain, but you want to &lt;br /&gt;register conversions in some outbound domain, say, &lt;b&gt;bar.com&lt;/b&gt;.  One way to handle this is to implement a&lt;br /&gt;strategy called &lt;i&gt;Google Analytics Cross Domain Linking&lt;/i&gt; as described in this &lt;a href="http://www.google.com/support/analytics/bin/answer.py?hl=en&amp;answer=55503"&gt;Analytics Help Center Article&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;This is a fine solution, but it suffers from two major problems.  First, it requires that you have the rights to modify pages in the outbound domain.  Secondly, and frankly (IMHO), it's kinda a pain in the ass to implement as well as being very error prone.  &lt;br /&gt;&lt;br /&gt;An alternative to tracking the loading of the outbound page, is to track the user's action of clicking the link to the outbound page.  This is neatly described in this &lt;a href="http://www.google.com/support/analytics/bin/answer.py?hl=en&amp;answer=55527"&gt;Analytics Help Center Article&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The only problem with this technique is that it really does not work very well.  It suffers from what we in the industry&lt;br /&gt;call a &lt;a href="http://en.wikipedia.org/wiki/Race_condition"&gt;Race Condition&lt;/a&gt;.  To understand this particular race condition, allow me to describe a little about how browsers work.&lt;br /&gt;&lt;br /&gt;When a web browser is loading a page and it encounters something like the following:&lt;br /&gt;&lt;pre&gt;&lt;div class=mycode&gt;... la la la&lt;br /&gt;&amp;lt;img src="a.jpg"&gt;&lt;br /&gt;la te da ...&lt;/div&gt;&lt;/pre&gt;The browser does not stop at the image tag in order to load the image.  In fact it does not even stop at the image tag to even &lt;i&gt;start&lt;/i&gt; loading the image.  It simply queues up a request to load that image at some later time.  Later in this case means really quick; probably in the next few milliseconds.  It may do this with another thread, or simply schedule it within the same thread.  The important point is that the HTTP request to the server which services the image &lt;i&gt;does not take place right away&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;Now, consider the following HTML:&lt;pre&gt;&lt;div class=mycode&gt;... One two three&lt;br /&gt;&amp;lt;a href="target.htm"&gt;Click Me!&amp;lt;/a&gt;&lt;br /&gt;... four five six ...&lt;/div&gt;&lt;/pre&gt;Here, when a visitor clicks on this link, the mechanism for loading and displaying the target page is very similar to the loading of the image above.  A request to start loading that page is queued up, and when the bytes of that response start arriving, the browser erases the current page and starts rendering the new page.  This is why after clicking on a link to a "distant" and slow site, you will continue to see the current page until the other responds -- there is no good reason to clear the screen on the current page until you have something new to display.&lt;br /&gt;&lt;br /&gt;One more vital piece of information needs to be mentioned here.  When a page is closed, in this case in favor of loading a new page, all the outstanding resource requests for the current, closing, page (like images) are abandoned.  This fact will place a crucial role in our race condition.&lt;br /&gt;&lt;br /&gt;Now, let's look at the code mentioned in the &lt;a href="http://www.google.com/support/analytics/bin/answer.py?hl=en&amp;answer=55527"&gt;How do I manually track clicks on outbound links?&lt;/a&gt; article:&lt;pre&gt;&lt;div class=mycode&gt;&amp;lt;a href="http://www.example.com" onClick="javascript: pageTracker._trackPageview('/outgoing/example.com');"&gt;&lt;/div&gt;&lt;/pre&gt;The script in the &lt;b&gt;onClick&lt;/b&gt; handler is intended to create a Google Analytics event (called /outgoing/example.com) with the &lt;b&gt;_trackPageview&lt;/b&gt; operation.  The way that _trackPageview works is that it makes a request to Google for an, essentially, empty image.  Along with that request, is the information about the visitor and what should be tracked.  It's how Google Analytics gets its information in order to create reports.  Now, just like the loading of an image tag, this request is also queued up by the browser -- &lt;i&gt;It's not immediately requested&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;Once the call to _trackPageview returns, the browser then starts the request for the outbound resource, "http://www.example.com", in this case.  This too is queued up, and when it start to come in, the page will clear and the new page will be rendered.&lt;br /&gt;&lt;br /&gt;Now, we have enough information to see where the race condition exists.&lt;br /&gt;&lt;br /&gt;If the request for example.com comes back really quickly, it is quite possible that the request for the Google Analytics tracking image has not yet taken place.  In fact, some browsers may prioritize requests for images below other requests, like those for other sites.  When this happens, all outstanding resource requests for the current page, and I'm thinking about the Google Analytics tracking request in particular, are abandoned.  This means that the event which was to be tracked via Analytics is lost to Analytics, as though it never happend.&lt;br /&gt;&lt;br /&gt;Bummer.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Give It Some Time ...&lt;/h3&gt;&lt;br /&gt;So, how does one track outbound links properly?&lt;br /&gt;&lt;br /&gt;The trick is to give the request for the Google Analytics tracking image enough time to take place.  This can be done by delaying the request for the outbound page with the following technique:&lt;pre&gt;&lt;div class=mycode&gt;&amp;lt;script type="text/javascript"&gt;&lt;br /&gt;function doGoal(that) {&lt;br /&gt;  try {&lt;br /&gt;    var pageTracker=_gat._getTracker("UA-123456-1");&lt;br /&gt;    pageTracker._trackPageview("http://www.example.com");&lt;br /&gt;    &lt;span class=code_bold&gt;setTimeout&lt;/span&gt;('document.location = "' + that.href + '"', 100)&lt;br /&gt;  }catch(err){}&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;a href="www.example.htm" onclick='doGoal(this);&lt;span class=code_bold&gt;return false&lt;/span&gt;;'&gt;Click me&amp;lt;/a&gt;&lt;/div&gt;&lt;/pre&gt;Here, notice that the onClick handler calls a function which, first, does not rely on the presence of a global pageTracker object to have been already set up.  It creates it's own tracking object.  This reduces the dependency on other scripts running on the page.&lt;br /&gt;&lt;br /&gt;Secondly, the return value from the onClick handler is &lt;b&gt;false&lt;/b&gt;.  This prohibits the browser from following the link as a consequence of the user clicking on the link.  This stops the browser from immediately navigating to example.com.&lt;br /&gt;&lt;br /&gt;Thirdly, notice the call to the &lt;b&gt;setTimeout&lt;/b&gt; function.  The setTimeout function's job is to execute a piece of code at some time in the future, without blocking the current script from continuing executing.  In this case, it's 1/10 of a second into the future, and the code to execute is that which is, essentially, the same as what the browser would have done if &lt;b&gt;true&lt;/b&gt; (or nothing) had been returned by the onClick handler.  Setting the location property of the document object with the outbound href will cause the page to navigate to that link.&lt;br /&gt;&lt;br /&gt;By delaying the outbound navigation by 1/10 of a second (which is generally not noticed by the user), the browser now has much more time to make the Google Analytics tracking request and the tracking event will be noticed and reported on by Google Analytics.&lt;br /&gt;&lt;br /&gt;Spiffy.&lt;br /&gt;&lt;br /&gt;The example above applies to tracking outbound links in Analytics, and is trivially adapted to tracking Google Website Optimizer goals as well.  You can see an example of a test page taking advantage of this technique &lt;a href="http://www.gwotricks.com/clickgoal/testpage.htm"&gt;here&lt;/a&gt; to track as the goal, clicking on a link.&lt;br /&gt;&lt;br /&gt;The essential code in the GWO sample page follows.  All that is really different is that the argument to _trackPageview is the token string for the GWO goal.&lt;pre&gt;&lt;div class=mycode&gt;&amp;lt;script type="text/javascript"&gt;&lt;br /&gt;function doGoal(that) {&lt;br /&gt;  try {&lt;br /&gt;    var pageTracker=_gat._getTracker("UA-7250447-1");&lt;br /&gt;    pageTracker._trackPageview(&lt;span class=code_bold&gt;"/2353623095/goal"&lt;/span&gt;);&lt;br /&gt;    setTimeout('document.location = "' + that.href + '"', 100)&lt;br /&gt;  }catch(err){}&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;a href="anotherpage.htm" onclick='doGoal(this);return false;'&gt;Click me&amp;lt;/a&gt;&lt;/div&gt;&lt;/pre&gt;&lt;br /&gt;Happy Clicking!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2825349447042335729-2576513173817915303?l=www.gwotricks.com%2Ftest%2Fdefault.htm' alt='' /&gt;&lt;/div&gt;</description><link>http://www.gwotricks.com/test/2009/07/tracking-outbound-links-right-way.html</link><author>noreply@blogger.com (Eric Vasilik)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>6</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-2825349447042335729.post-1549933263398510198</guid><pubDate>Tue, 19 May 2009 05:05:00 +0000</pubDate><atom:updated>2009-05-19T01:03:24.638-07:00</atom:updated><title>Server-Side Dynamic Section Variations</title><description>&lt;p&gt;This technique is one of my favorites because it involves some pretty "clever" (euphemism for twisted) JavaScript.  But don't let this scare you, the script works on all the browsers and is as fail-safe as the scripting that Website Optimizer requests you place on your sites by default.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Multi-Variate Experiments "Out of the Box"&lt;/h3&gt;&lt;br /&gt;First, let's revisit certain aspects of GWO pertinent to this technique.  By default, GWO handles multi-variate experiments in the following way:&lt;br /&gt;&lt;br /&gt;&lt;img src="/test/2009/05/default.png"&gt;&lt;br /&gt;&lt;br /&gt;Your test page and the default content for your experiment sections are served directly from your web server.  If alternative content has been chosen to be displayed to a visitor, that alternative content is served from a Google server.&lt;br /&gt;&lt;br /&gt;Now, this poses a particular limitation: the alternative content must be static in nature.  The reason behind this is in the fact that, in the default setup process of a multi-variate experiment, you are requested to input the alternative content into GWO's user interface, and that content is simply served back to your test page on demand where it replaces the default content in the page for visitors selected to see the alternative content.&lt;br /&gt;&lt;br /&gt;This means that if you wanted to customize that alternative content differently for each visitor, you don't get a chance to do so.  For example, you might want to include the customer's name in the alternative content.  Or, you might want to serve a promotion customized for the given customer.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Alternative Content Served from Your Webserver&lt;/h3&gt;&lt;br /&gt;The technique I am about to discuss allows you to serve all content, default and alternative, directly from your web server:&lt;br /&gt;&lt;br /&gt;&lt;img src="/test/2009/05/dynserver.png"&gt;&lt;br /&gt;&lt;br /&gt;Here, the Google server does not serve any alternative content.  It only serves back an indicator (an integer) of which content should be show to a given visitor.  All the possible variations for the sections are rendered into the web page by your web server where you have complete dynamic control over the content of those variations.  In the following, I will show you the scripts you need to generate along with that content in order to show one of either your default content or variations.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Size of Alternatives&lt;/h3&gt;&lt;br /&gt;That said, one should be careful when using this technique because it requires you to render all possible section variations into the page.  Because even though your web server knows what the content of the alternatives are, it does not know which alternative will be chosen for a visitor to your test page.  Contact with the Google server is required for that, and the logic about which content to show to the visitor must be executed in the browser client.&lt;br /&gt;&lt;br /&gt;So, if the number and size of all the alternative section variations is not too large, you can use this technique.  Many times, this is the case.  Even if you define your entire page to be a single section, this technique may work for you because only the HTML of the alternative need be present in your page.  Any other resources, like images, scripts or style sheets, which are specific to an alternative variation will be loaded if that alternative variation is chosen for a visitor.  Content which was not chosen for the visitor will not even be parsed by the browser, it will essentially be thrown away.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Creating the Experiment&lt;/h3&gt;&lt;br /&gt;To use this technique, you begin by creating a regular multi-variate experiment.  Give the experiment a name, test page and goal page.  When asked to add the GWO scripts to the page, add the control script in the normal way.  And, add the tracking scripts in the normal way.  &lt;br /&gt;&lt;br /&gt;However, do not follow the default instructions for adding section scripts.  I have prepared an example test page you can look at which illustrates the alternative to the default section scripts which allows you to serve alternative section variations from your web server:&lt;br /&gt;&lt;br /&gt;&lt;div class=mycode&gt;&lt;a href="http://www.gwotricks.com/dynserver/testpage.htm"&gt;Server Side Sections Example&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;First, you will want to declare the number and names of the server-side dynamic experiment sections you plan to test.  Sections are normally declared as a result of surrounding the default content of a section with the standard GWO sections scripts.  But, because we are not using those, you need to use an alternative.  So, to declare a single section with the name "Section1", place the following immediately after the Control Script:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;div class=mycode&gt;&amp;lt;!-- utmx section name="Section1" --&amp;gt;&lt;/div&gt;&lt;/pre&gt;You can repeat this kind of comment to declare up to 8 sections.  For example:&lt;br /&gt;&lt;pre&gt;&lt;div class=mycode&gt;&amp;lt;!-- utmx section name="Section1" --&amp;gt;&lt;br /&gt;&amp;lt;!-- utmx section name="Section2" --&amp;gt;&lt;br /&gt;&amp;lt;!-- utmx section name="Section3" --&amp;gt;&lt;/div&gt;&lt;/pre&gt;&lt;br /&gt;Note that you can mix regular GWO multi-variate section with server-side dynamic sections.  Simply include the standard GWO style sections as described in the install instructions.&lt;br /&gt;&lt;h3&gt;Instrumenting the Sections&lt;/h3&gt;&lt;br /&gt;The following script is the entire definition of the section from my example page.  I show you in its entirety here, and will dissect it after.  Note that the dynamic content for each variation is highlighted.  These are the parts of the page you get to dynamically generate.  Only one of them will be show to a given visitor, the others will be stripped away.&lt;br /&gt;&lt;pre&gt;&lt;div class=mycode&gt;&amp;lt;script&amp;gt;&lt;br /&gt;var GWO_Section1 = utmx("variation_number", "Section1");&lt;br /&gt;if (GWO_Section1 != undefined &amp;amp;&amp;amp; GWO_Section1 != 0) document.write('&amp;lt;no' + 'script&amp;gt;');&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;span class=code_bold&gt;Default content - shown by default&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;lt;/noscript&amp;gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&amp;lt;script&amp;gt;&lt;br /&gt;if (GWO_Section1 == 1) document.write('&amp;lt;/noscript a="');&lt;br /&gt;&amp;lt;/script&amp;gt;&amp;lt;!--"&amp;gt;&lt;br /&gt;&lt;span class=code_bold&gt;Alternative content 1&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;lt;script&amp;gt;document.write('&amp;lt;'+'!'+'-'+'-')&amp;lt;/script&amp;gt;--&amp;gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&amp;lt;script&amp;gt;&lt;br /&gt;if (GWO_Section1 == 2) document.write('&amp;lt;/noscript a="');&lt;br /&gt;&amp;lt;/script&amp;gt;&amp;lt;!--"&amp;gt;&lt;br /&gt;&lt;span class=code_bold&gt;Alternative content 2&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;lt;script&amp;gt;document.write('&amp;lt;'+'!'+'-'+'-')&amp;lt;/script&amp;gt;--&amp;gt;&lt;/div&gt;&lt;/pre&gt;&lt;br /&gt;&lt;h3&gt;The Default Content&lt;/h3&gt;&lt;br /&gt;Like any GWO experiment, the default content is encoded in your test pages, and if JavaScript is not present or disabled, or there is any malfunction anywhere, the default content will be presented to your visitors.  With this technique, the default content is handled with this script:&lt;br /&gt;&lt;pre&gt;&lt;div class=mycode&gt;&amp;lt;script&amp;gt;&lt;br /&gt;var GWO_Section1 = utmx("variation_number", "Section1");&lt;br /&gt;if (GWO_Section1 != undefined &amp;amp;&amp;amp; GWO_Section1 != 0) document.write('&amp;lt;no' + 'script&amp;gt;');&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;span class=code_bold&gt;Default content - shown by default&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;lt;/noscript&amp;gt;&lt;br /&gt;&lt;/div&gt;&lt;/pre&gt;Here, the script code firsts obtains the number of the variation for the section named "Section1" chosen for the current visitor:&lt;br /&gt;&lt;pre&gt;&lt;div class=mycode&gt;var GWO_Section1 = utmx("variation_number", "Section1");&lt;/div&gt;&lt;/pre&gt;This call to the utmx function will return a &lt;b&gt;0&lt;/b&gt; (zero) or &lt;b&gt;undefined&lt;/b&gt; if the visitor should see the default content.  This value is saved in a global variable for use in subsequent alternative content scripts.  Note that the &lt;b&gt;utmx&lt;/b&gt; function is defined by the Control Script which needs to have been executed before the call to the utmx function in this script.&lt;br /&gt;&lt;br /&gt;Then, if alternative content has been chosen for this visitor, the default content is hidden from the visitor with the second line of code:&lt;pre&gt;&lt;div class=mycode&gt;if (GWO_Section1 != undefined &amp;amp;&amp;amp; GWO_Section1 != 0) document.write('&amp;lt;no' + 'script&amp;gt;');&lt;/div&gt;&lt;/pre&gt;By document.writing a beginning &lt;b&gt;&amp;lt;noscript&amp;gt;&lt;/b&gt; tag, the content after the script and up to the first &lt;b&gt;&amp;lt;/noscript&amp;gt;&lt;/b&gt; tag will be consumed and ignored by the parser.  This requires that your default content not contain any noscript tags (beginning or ending).  This is exactly the same technique used by GWO for standard installations of multi-variate experiments.  The only difference is that here we are just removing the default content, but the standard GWO multi-variate technique document.writes the alternative content to replace the default content before writing the &lt;b&gt;&amp;lt;noscript&amp;gt;&lt;/b&gt; tag to eliminate the default content.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;The Alternative Content&lt;/h3&gt;&lt;br /&gt;Now, for each variation of alternative content for a given section, you will need a script like this:&lt;br /&gt;&lt;pre&gt;&lt;div class=mycode&gt;&amp;lt;script&amp;gt;&lt;br /&gt;if (GWO_Section1 == &lt;span class=code_bold&gt;1&lt;/span&gt;) document.write('&amp;lt;/noscript a="');&lt;br /&gt;&amp;lt;/script&amp;gt;&amp;lt;!--"&amp;gt;&lt;br /&gt;&lt;span class=code_bold&gt;Alternative content 1&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;lt;script&amp;gt;document.write('&amp;lt;'+'!'+'-'+'-')&amp;lt;/script&amp;gt;--&amp;gt;&lt;/div&gt;&lt;/pre&gt;Note that the &lt;b&gt;1&lt;/b&gt; indicates that this script is customized for the first alternative.  The second alternative will have the number &lt;b&gt;2&lt;/b&gt;, the third &lt;b&gt;3&lt;/b&gt;, etc.  The larger highlighted part is your dynamically generated alternative content for the first alternative.  Simply have your web server surround the alternative content with the other text.&lt;br /&gt;&lt;br /&gt;The first line of the script determines if this alternative was chosen to be viewed by the visitor and document.writes some content designed to cause the variation to be shown to the visitor:&lt;pre&gt;&lt;div class=mycode&gt;if (GWO_Section1 == 1) document.write('&amp;lt;/noscript a="');&lt;/div&gt;&lt;/pre&gt;To understand this better, consider what this content would look like if scripting is disabled, or the value of &lt;b&gt;GWO_Section1&lt;/b&gt; does not have the value &lt;b&gt;1&lt;/b&gt;.  That is, there is no script:&lt;br /&gt;&lt;pre&gt;&lt;div class=mycode&gt;&amp;lt;!--"&amp;gt;&lt;br /&gt;Alternative content 1&amp;lt;br&amp;gt;&lt;br /&gt;&amp;lt;script&amp;gt;document.write('&amp;lt;'+'!'+'-'+'-')&amp;lt;/script&amp;gt;--&amp;gt;&lt;/div&gt;&lt;/pre&gt;This entire block of HTML is nothing more than one large comment.  In fact, the alternative content is hidden by default by the fact that it is embedded inside a comment.  This means that the alternative content &lt;i&gt;must not have any comments&lt;/i&gt; in it.  Note that even the script at the end of the HTML is also inside the comment.&lt;br /&gt;&lt;br /&gt;Now, look carefully at what is written if this section variation has been chosen to be displayed to the visitor:&lt;br /&gt;&lt;pre&gt;&lt;div class=mycode&gt;&amp;lt;/noscript a="&lt;/div&gt;&lt;/pre&gt;This is the beginning of an ending noscript tag.  Note that there is no &lt;b&gt;&amp;gt;&lt;/b&gt; terminating the tag.  Also, in this tag there is the beginning of an attribute.  Notice, also, that the value of the attribute is not present and that the ending double quote is not present.  That is not two single quotes.  It is a single double quote.&lt;br /&gt;&lt;br /&gt;Recall that the way that document.write works is that the written text is, essentially, inserted after the end of the script where the browser parser will resume its parsing after the script has executed.  Again, by stripping away the first script tag, let's look at what the parser will encounter:&lt;br /&gt;&lt;pre&gt;&lt;div class=mycode&gt;&amp;lt;/noscript a="&amp;lt;!--"&amp;gt;&lt;br /&gt;Alternative content 1&amp;lt;br&amp;gt;&lt;br /&gt;&amp;lt;script&amp;gt;document.write('&amp;lt;'+'!'+'-'+'-')&amp;lt;/script&amp;gt;--&amp;gt;&lt;/div&gt;&lt;/pre&gt;Here the parser sees an ending noscript tag with an attribute whose value are the characters which begin a comment.  The thing to know here is that HTML parsers allow beginning comment sequences inside attribute values.  This is the clever (twisted) part I eluded to earlier.&lt;br /&gt;&lt;br /&gt;Now, it should be apparent why there was the &lt;span class=code_bold&gt;"&amp;gt;&lt;/span&gt; characters immediately after the beginning comment character sequence: &lt;span class=code_bold&gt;&amp;lt;!--&lt;/span&gt;.  It is there to terminate the dynamically written ending noscript tag.  This tag "eats" the beginning comment token.  Yummy.&lt;br /&gt;&lt;br /&gt;This allows the parser to parse and display the alternative content.  Now, all we need to do is deal with the remaining ending comment token!  This is done by the last part of the script:&lt;br /&gt;&lt;pre&gt;&lt;div class=mycode&gt;&amp;lt;script&amp;gt;document.write('&amp;lt;'+'!'+'-'+'-')&amp;lt;/script&amp;gt;&lt;/div&gt;&lt;/pre&gt;Which injects a beginning comment token which is terminated by the remaining ending comment token, statically present in the page.  Without this document.write, the "&lt;b&gt;--&amp;gt;&lt;/b&gt;" would appear in the page when this alternative content was chosen for the visitor.&lt;br /&gt;&lt;br /&gt;This is how each alternative variation is handled.  Simply do the above for each alternative section.  Each one will have the server generated content of the variation.  Each script will have the number of the variation encoded in it.  1 for the first alternative, 2 for the second, etc.&lt;br /&gt;&lt;br /&gt;You can repeat this sequence of scripts for a section as many times on your page(s) as you want to hide/show the default/alternative content for that section.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Setting Up the Variations in GWO&lt;/h3&gt;&lt;br /&gt;Even though this technique requires you generate all your alternative content into the page, you will still need to create section variations in Step 3 of the GWO user interface for each section in your test.  The only difference is that you do not supply any content for these variations.  The reason for this is that GWO still needs to know how many variations each server-side dynamic section has for the purposes of choosing which variation visitors will see and reporting results.  For example:&lt;br /&gt;&lt;br /&gt;&lt;img src="/test/2009/05/step3.png"&gt;&lt;br /&gt;&lt;br /&gt;Shows the section named "Section1" with two (2) variations created for it.  I give each variation a name for reporting purposes, but I do not need to give it any content.&lt;br /&gt;&lt;br /&gt;After Doing this, all that is left to do is preview the experiment to make sure the scripts are working and launch the experiment!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2825349447042335729-1549933263398510198?l=www.gwotricks.com%2Ftest%2Fdefault.htm' alt='' /&gt;&lt;/div&gt;</description><link>http://www.gwotricks.com/test/2009/05/server-side-dynamic-section-variations.html</link><author>noreply@blogger.com (Eric Vasilik)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-2825349447042335729.post-1696109696907232022</guid><pubDate>Fri, 10 Apr 2009 06:07:00 +0000</pubDate><atom:updated>2009-04-10T00:45:41.668-07:00</atom:updated><title>Fragmented Sections</title><description>&lt;p&gt;&lt;br /&gt;The default setup for a multi-variate experiment asks you to place what are called "Section Tags" on your test page. For example consider a header for a fictitious pet food web site:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;div class="mycode"&gt;&lt;span class="code_bold"&gt;&amp;lt;script&gt;utmx_section('Heading')&amp;lt;/script&gt;&lt;/span&gt;&lt;br /&gt;World's best pet food!&lt;br /&gt;&lt;span class="code_bold"&gt;&amp;lt;/noscript&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;/pre&gt;The purpose of these tags is to identify a contiguous span of HTML on your test page with which you would like to experiment. In the GWO online tool, you would enter the alternative variations for this section. For example:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;img src="http://www.blogger.com/test/2009/04/normal.png" /&gt;&lt;/center&gt;&lt;br /&gt;&lt;p&gt;This allows you to specify an alternative which will replace the original content on your test page. In fact, everywhere this pet food website mentions the phrase "World's best pet food!", you could instrument that phrase with the scripts above to have a visitor to your site experience every instance of the phrase on the site with the &lt;b&gt;same&lt;/b&gt; alternative variation.&lt;br /&gt;&lt;p&gt;But, what if you want to vary multiple parts of a page (or pages) on your site in concert with each other? For example, let's say that our fictitious pet food web site shows a letter to visitors, like so:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;img src="http://www.blogger.com/test/2009/04/original.png" border="1" /&gt;&lt;/center&gt;&lt;br /&gt;&lt;p&gt;Then let's say that you want to have multiple variations of the letter, each with a different tone in the salutation and signature. For example, an informal tone:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;img src="http://www.blogger.com/test/2009/04/informal.png" border="1" /&gt;&lt;/center&gt;&lt;br /&gt;&lt;p&gt;Or, a formal tone:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;img src="http://www.blogger.com/test/2009/04/formal.png" border="1" /&gt;&lt;/center&gt;&lt;br /&gt;&lt;p&gt;Now, you could implement this in the same manner as the section shown above. However, because the salutation and signature are separated by the body of the letter, you would have to include an entire copy of the body in each variation of the section, where the different variations differ only by the salutation at the beginning and the corresponding signature at the end.&lt;br /&gt;&lt;p&gt;Now, in this simple example the body is not that large, but the redundancy runs the risk of introducing different bodies which would foil the experiment. And, in the case where the body is not small, you would not want to replicate the body. Furthermore, it might be the case that the two parts of your site you want to vary in concert with each other are not on the same page. The standard section tagging technique breaks down entirely in this case.&lt;br /&gt;&lt;p&gt;The technique I am about to explain will allow you to experiment with your site in such a way as to only require you to alter the actual pieces of the page you want to change, but allow you to have those pieces change together. This is what I call &lt;i&gt;Fragmented Sections&lt;/i&gt;. First, a look at what you would enter into the GWO online tool for a variation of our letter's Tone section:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;img src="http://www.blogger.com/test/2009/04/fragmented.png" /&gt;&lt;/center&gt;&lt;br /&gt;&lt;p&gt;What I've done here is to place what I call &lt;b&gt;Fragments&lt;/b&gt; of a single section variation surrounded by special %% tokens which identify the fragments with monotonically increasing numbers starting with 1 (fragments cannot have %% sequences in them, or a different token will need to be chosen). Thus, the salutation (the first fragment) of the Formal variation of the Tone section is represented by:&lt;br /&gt;&lt;br /&gt;&lt;div class="mycode"&gt;%%Frag 1%%Dear Sir/Madam%%&lt;/div&gt;&lt;br /&gt;and the signature (the second fragment) is represented by:&lt;br /&gt;&lt;br /&gt;&lt;div class="mycode"&gt;%%Frag 2%%Sincerely%%&lt;/div&gt;&lt;br /&gt;The value for the informal variation of the section would look like:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;img src="http://www.blogger.com/test/2009/04/informalv.png" /&gt;&lt;/center&gt;&lt;br /&gt;This is a single section with multiple parts to it. Now, how does one use these multiple parts in the actual web page? Here is what the letter part of our pet food web site would look like:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;div class="mycode"&gt;&lt;span class="code_bold"&gt;&amp;lt;p&gt;&amp;lt;script&gt;write_frag('Tone', 1)&amp;lt;/script&gt;&lt;b&gt;Hello&lt;/b&gt;&amp;lt;/noscript&gt;&lt;/span&gt;,&lt;br /&gt;&amp;lt;p&gt;&lt;br /&gt;We're so sure your pet will flip out over this food, we&lt;br /&gt;offer a double your money back guarantee! If your pet&lt;br /&gt;is not satisfied in 30 days of purchase, just return the&lt;br /&gt;unused portion of the food and a notorized letter from&lt;br /&gt;your pet explaining why the food was less than perfect.&lt;br /&gt;&amp;lt;p&gt;&lt;br /&gt;&lt;span class="code_bold"&gt;&amp;lt;script&gt;write_frag('Tone', 2)&amp;lt;/script&gt;&lt;b&gt;Thanks&lt;/b&gt;&amp;lt;/noscript&gt;&lt;/span&gt;,&amp;lt;br&gt;&lt;br /&gt;The Pet Food Company&lt;/div&gt;&lt;/pre&gt;I've highlighted the two section fragments. They are very similar to the standard tags one would use, but instead of calling the &lt;b&gt;utmx_section&lt;/b&gt; function, they call a function called &lt;b&gt;write_frag&lt;/b&gt;. Also notice that the default version of the section fragments are encoded in the page, surrounded by the function call and a &lt;b&gt;&amp;lt;/noscript&gt;&lt;/b&gt; tag - just like standard section tagging.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now, the definition of the &lt;b&gt;write_frag&lt;/b&gt; function:&lt;br /&gt;&lt;pre&gt;&lt;div class="mycode"&gt;&amp;lt;!-- utmx section name="Tone" --&gt;&lt;br /&gt;&amp;lt;script&gt;&lt;br /&gt;function write_frag(section, frag_num) {&lt;br /&gt;var content = utmx('variation_content', section);&lt;br /&gt;if (content) {&lt;br /&gt;var token = '%%Frag ' + frag_num + '%%';&lt;br /&gt;var start = content.indexOf(token) + token.length;&lt;br /&gt;var finish = content.indexOf('%%', start);&lt;br /&gt;document.write(content.substring(start, finish));&lt;br /&gt;document.write('&amp;lt;no' + 'script&gt;');&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&gt;&lt;/div&gt;&lt;/pre&gt;The first line of this block of HTML is a special comment which declares the presence of the Tone section to GWO. GWO normally detects the section of a multi-variate experiment by looking for the standard section tags. But, because those are not present, this comment is an alternative way of declaring the section.&lt;br /&gt;&lt;p&gt;The write_frag function takes two arguments: a section name and a fragment number. What the function does is acquire the value of the the section's variation as it was entered into GWO:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;div class="mycode"&gt;var content = utmx('variation_content', section);&lt;/div&gt;&lt;/pre&gt;This call's the &lt;b&gt;utmx&lt;/b&gt; function which is &lt;a href="http://www.gwotricks.com/2009/03/advanced-test-page-functionality.html"&gt;detailed in another article&lt;/a&gt;. This call returns one of the %%'ed variations defined for the specified section which was chosen by GWO for this visitor to see. If an alternative variation is not returned, then the function does nothing else, and the default content is displayed. However, if an alternative variation is returned, then the function searches that variation for a block of text surrounded by the special %% tokens. The start token takes the form &lt;span class="code_bold"&gt;%%Frag #%%&lt;/span&gt; where # is replaced with the number of the fragment. In this example, there are two fragments, but you could have as many as you want.&lt;br /&gt;&lt;p&gt;Then, after isolating the value of the fragment, it &lt;b&gt;document.write&lt;/b&gt;'s this along with a &lt;b&gt;&amp;lt;/noscript&gt;&lt;/b&gt; tag. This is exactly what the &lt;b&gt;utmx_section&lt;/b&gt; does for you in the standard version of section tags. This causes the browser's parser to encounter and display the fragment's value while removing the original's value.  &lt;br /&gt;&lt;p&gt;Thus, with this technique, you can define sections which need not be contiguous.  I have a &lt;a href=""&gt;web page illustrating this very technique&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2825349447042335729-1696109696907232022?l=www.gwotricks.com%2Ftest%2Fdefault.htm' alt='' /&gt;&lt;/div&gt;</description><link>http://www.gwotricks.com/test/2009/04/fragmented-sections_09.html</link><author>noreply@blogger.com (Eric Vasilik)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item></channel></rss>
