Changeset 1449272
- Timestamp:
- 07/05/2016 01:43:25 PM (10 years ago)
- Location:
- simple-content-experiments/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (1 diff)
-
simple-content-experiments.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-content-experiments/trunk/readme.txt
r1398485 r1449272 138 138 139 139 == Changelog == 140 = 2.5 = 141 Fix script order execution issue. 142 140 143 = 2.4.1 = 141 144 Just updating version number to WordPress.org recognizes new update date -
simple-content-experiments/trunk/simple-content-experiments.php
r1398485 r1449272 2 2 /** 3 3 * @package content-experiments 4 * @version 2. 4.14 * @version 2.5 5 5 */ 6 6 /* … … 8 8 Description: Shortcodes to create Google Content Experiments elements in a page 9 9 Author: Lon Koenig (Firebrand LLC) 10 Version: 2. 4.110 Version: 2.5 11 11 Author URI: //firebrand.net/ 12 12 13 Calls the Google Experiments API: 14 https://developers.google.com/analytics/solutions/experiments-client-side#implement-send 13 15 Implement the following shortcodes: 14 16 [experiment][/experiment] … … 45 47 private static $experiment_id = null; 46 48 private static $errmsg = ''; 49 public $debug_enable = 'false'; 47 50 48 51 public function __construct() { … … 157 160 id: "", 158 161 variant_count:0, 159 selected: 0 160 } 162 selected: 0, 163 debug: ' . $this->debug_enable . ', 164 analytics_package: "ua", // default is Universal Analytics 165 event: { 166 category: "experiment", 167 action: "select", 168 label: "", 169 value: 0 170 }, 171 dbgmsg: function(str){ 172 if (content_experiment.debug){ console.log(str);} 173 } 174 }; 161 175 162 176 jQuery(document).ready(function() { 163 177 var ex_list = {}; 178 179 // Determine which version of Google Analytics is being used 180 if (typeof dataLayer !== "undefined" && typeof dataLayer.push === "function" && !options.gtmOverride) { 181 //standardEventHandler = function(data) { dataLayer.push(data); }; 182 content_experiment.analytics_package = "gtm"; 183 } else if (typeof _gaq !== "undefined" && typeof _gaq.push === "function") { 184 content_experiment.analytics_package = "classic"; 185 } 186 187 164 188 jQuery( ".contentexperimentvariant" ).each( 165 189 function( ) { 166 190 var v_id = jQuery( this ).attr("data-contentexperimentid"); 167 console.log(v_id);168 169 191 if(typeof ex_list[v_id] == "undefined") { 170 192 ex_list[v_id] = 0; … … 180 202 content_experiment.id = keys[i]; 181 203 content_experiment.variant_count = ex_list[content_experiment.id]; 182 con sole.log(content_experiment.id);204 content_experiment.dbgmsg(content_experiment.id); 183 205 jQuery.getScript( 184 206 "//www.google-analytics.com/cx/api.js?experiment=" + content_experiment.id, … … 209 231 //Execute the chosen view: 210 232 var selected_variation = content_experiment.selected; 211 //console.log("chosenExperiment = " + content_experiment.id + "\nchosenVariation = " + selected_variation);212 //console.log("number of variations: " + content_experiment.variant_count);233 content_experiment.dbgmsg("chosenExperiment = " + content_experiment.id + "\nchosenVariation = " + selected_variation); 234 content_experiment.dbgmsg("number of variations: " + content_experiment.variant_count); 213 235 for ( i = 1; i <= content_experiment.variant_count; i++) { 214 236 if ( (i - 1) == selected_variation) { // 0 based 215 // console.log("showing variant " + i + content_experiment.id + "__" + i);237 // content_experiment.dbgmsg("showing variant " + i + content_experiment.id + "__" + i); 216 238 jQuery("#" + content_experiment.id + "__" + i).show(); 217 239 } else { 218 // console.log("hiding variant " + i + content_experiment.id + "__" + i);240 // content_experiment.dbgmsg("hiding variant " + i + content_experiment.id + "__" + i); 219 241 jQuery("#" + content_experiment.id + "__" + i).remove(); 220 242 } 221 243 } 244 // sometimes the scripts load in the wrong order and Google Analytics won\'t get an event from chooseVariation() 245 // Send any event to analytics to solve this: 246 content_experiment.dbgmsg("analytics type: " + content_experiment.analytics_package); 247 switch (content_experiment.analytics_package){ 248 case "classic": 249 _trackEvent( // category, action, opt_label, opt_value, opt_noninteraction 250 content_experiment.event.category, 251 content_experiment.event.action, 252 content_experiment.event.label, 253 content_experiment.event.value, 254 true 255 ); 256 content_experiment.dbgmsg("_trackEvent posted "); 257 break; 258 259 case "gtm": 260 dataLayer.push({ 261 "event" : "GAEvent", 262 "eventCategory" : content_experiment.event.category, 263 "eventAction" : content_experiment.event.action, 264 "eventLabel" : content_experiment.event.label, 265 "eventValue" : content_experiment.event.value, 266 "nonInteraction": true 267 }); 268 content_experiment.dbgmsg("dataLayer.push( posted "); 269 break; 270 271 default: 272 var ga_name = "ga"; 273 if (typeof __gaTracker === "function"){ 274 ga_name = "__gaTracker"; 275 } 276 277 window[ga_name]("send", "event", 278 content_experiment.event.category, 279 content_experiment.event.action, 280 content_experiment.event.label, 281 content_experiment.event.value, 282 { nonInteraction: true } 283 ); 284 content_experiment.dbgmsg( ga_name + " event posted "); 285 } 222 286 223 287 } … … 259 323 260 324 261 262 325 } 263 326
Note: See TracChangeset
for help on using the changeset viewer.