All Collections
Using Marketo Audiences in Optimizely X
Using Marketo Audiences in Optimizely X
Arun Sivashankaran avatar
Written by Arun Sivashankaran
Updated over a week ago

When a visitor lands on your site, the FunnelEnvy snippet makes a server call to identify the audiences they're in. It's possible Optimizely will execute, and evaluate audience conditions, before this call returns, meaning Optimizely will fail to correctly identify visitors in your Marketo audience.

The solution to this involves creating an Optimizely Page with Callback Activation. You'll need to add custom code so the Page activates after the FunnelEnvy snippet runs, and only if the visitor is in the audience of interest.

In Optimizely, create a new Page and set the target URL(s). Under Page Settings > Triggers, choose "When a callback is called". Paste the following code:

function callback(activate, options) {
  /* Check dataLayer for event adding visitor to audience */
  function isInAudience() {
    var eventPath = ['event'];
    var bsPath = ['backstage', 'audiences', AUDIENCE_SLUG];
    return window.dataLayer.some(function(item) {
      return (getProp(bsPath, item) && getProp(eventPath, item) === 'backstage.updatedAudiences');
  }  /* Return a nested property from an object, or null */
  function getProp(path, object) {
    function contains(obj, prop) {
      return obj && obj[prop] ? obj[prop] : null;
    return path.reduce(contains, object);
  }  /* IIFE to poll for window.optimizely.feDone, then evaluate audience */
  (function pollForFeDone() {
    var isDone = getProp(['optimizely', 'feDone'], window);
    if (isDone === true) {
      if (isInAudience())
    } else {
      return setTimeout(pollForFeDone, 100);

In the second line, where you see [/* TODO ADD STRING */], you'll need to add a string (in quotes) that corresponds to the name of your Marketo Audience. To generate this string, click the Audience:

Then note the last part of the URL in your browser's address bar:

In this example, the second line of Callback Activation code would look like this:

        var AUDIENCE_SLUG = 'downloadWhitepaper';

That's it! You can now launch an Optimizely experiment targeted to that Page, and it will activate as soon as your audience data is available.

Did this answer your question?