diff --git a/lib/cohorts.js b/lib/cohorts.js index 5318adf..d6317ef 100644 --- a/lib/cohorts.js +++ b/lib/cohorts.js @@ -14,8 +14,8 @@ Cohorts = (function() { throw(" _gaq object not found: It looks like you haven't correctly setup the asynchronous Google Analytics tracking code, and you are using the default GoogleAnalyticsAdapter."); } }, - onInitialize: function(inTest, testName, cohort) { - if(inTest) { + onInitialize: function(inTest, testName, cohort, new_to_this_test) { + if(inTest && new_to_this_test) { this.trackEvent(this.nameSpace, testName, cohort + ' | Total'); } }, @@ -71,8 +71,13 @@ Cohorts = (function() { // Determine whether user should be in the test var in_test = this.inTest(); - if(in_test === null) // haven't seen this user before + var new_to_this_test = null; + if(in_test === null) { // haven't seen this user before in_test = Math.random() <= this.options.sample; + if (in_test) new_to_this_test = true; + } + else + new_to_this_test = false; if(in_test) { this.setCookie('in_test', 1); @@ -86,7 +91,7 @@ Cohorts = (function() { } else { var chosen_cohort = this.getCohort(); } - this.options.storageAdapter.onInitialize(in_test, this.options.name, chosen_cohort); + this.options.storageAdapter.onInitialize(in_test, this.options.name, chosen_cohort, new_to_this_test); // call the onChosen handler, if it exists if(this.options.cohorts[chosen_cohort].onChosen) diff --git a/test/dev_storageAdapter.html b/test/dev_storageAdapter.html new file mode 100755 index 0000000..615a42f --- /dev/null +++ b/test/dev_storageAdapter.html @@ -0,0 +1,82 @@ + + + + Cohorts Test with StorageAdapter + + + + + +

+ This is a big header +

+ +

+ This is a small header +

+ + + + + \ No newline at end of file diff --git a/test/test_storageAdapter.html b/test/test_storageAdapter.html index 5d39165..48f9a30 100644 --- a/test/test_storageAdapter.html +++ b/test/test_storageAdapter.html @@ -53,8 +53,8 @@

throw(" _gaq object not found: It looks like you haven't correctly setup the asynchronous Google Analytics tracking code, and you are using the default GoogleAnalyticsAdapter."); } }, - onInitialize: function(inTest, testName, cohort) { - if(inTest) { + onInitialize: function(inTest, testName, cohort, new_to_this_test) { + if(inTest && new_to_this_test) { this.trackEvent(this.nameSpace, testName, cohort + ' | Total'); } },