Reputation: 379
I'm trying to implement Google server-side experiments by following this reference: https://developers.google.com/analytics/solutions/experiments-server-side
My goal is to let Google decide which variation I should show to user from the experiment. I have figured out that this can be achieved by setting "servingFramework" option to API.
I'm stuck on which steps I should complete to get the variation chosen by Google?
The main question is - how can I achieve the same results as from the following example, but server-side:
var variation = cxApi.chooseVariation();
This is necessary because first of all, I need to get variation and just after that to show it to the user.
Upvotes: 2
Views: 489
Reputation: 754920
According to deividaspetraitis in a comment:
I have solved it like this:
$googleAPI = ''; // googleAPI
$serviceExperiments = $googleAPI->getService('Experiments')>setId("experiment_id");
$serviceExperiments->setCacheTtl(500);
$serviceExperiments->setCacheDir(CACHE);
$experimentData = $serviceExperiments->getData();
# $mt_random = (mt_rand(0, 10) / 100 );
$mt_random = (float) number_format((float)rand()/(float)getrandmax(), 2, '.', '');
if( ($mt_random <= $experimentData["participation"]) !== true ) { return; }
Upvotes: 0