0

Is there a way to get Google Optimize to return specific data values or even JSON objects for use with experiment callbacks?

We are using Google Optimize without using the visual editor. Instead, we simply want it to indicate which layout pattern to request from a separate API we set up a long time ago.

function gtag() {dataLayer.push(arguments)}

function implementExperimentA(value) {
  if (value ==  '0') {
    // Provide code for visitors in the original.
  } else if (value == '1') {
    // Provide code for visitors in first variant.
  } else if (value == '2') {
    // Provide code for visitors in section variant.
  }
  ...
}

gtag('event', 'optimize.callback', {
    name: '<experiment_id_A>',
    callback: implementExperimentA
 });

This code example is everywhere and basically what I want to use, but instead of value==1 etc, I want to to be able to use value as a request parameter.

$.get(url, {layoutId: value});

LayoutIds are not integers however. They are unique strings. So again, my question: Is there a way to get Google Optimize to return specific data values or even JSON objects for use with experiment callbacks? Or do I need to map all the Experiment indexes to their correlating API parameter values within my javascript code?

Will Reese
  • 2,801
  • 2
  • 15
  • 27
  • Based on experience, I'd say no, but I have no documentation to support this. How would Optimize know the variant-API value mapping to return, which you would set up yourself in your code? I'm not aware of any ways to feed such data into Optimize. – kgrg May 09 '19 at 04:56
  • I was hoping that I might be able to indicate the layoutId as a property of a variation that would be exposed to my callback. – Will Reese May 09 '19 at 06:37
  • You might do better to use a client side assignment library like https://mojito.mx/ or roll the assignment logic yourself and then report exposures back to Google Optimize through its API: https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/?#ga:experimentCombination ... then you won't have to wait for the API to return a response. – Robert Kingston Nov 08 '19 at 04:54

0 Answers0