- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Creation of a real time Audience from page level JavaScript variables
Creation of a real time Audience from page level JavaScript variables
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Hi guys, looking for some technical guidance - hopefully a simple one - how can I pass audience data from a page to Optimziely?
More specifically how can I pass a key/value pair from an on page JavaScript variable to Optimizely so that I can create an Audience / segment and return an on page experience utilizing said segment derived from the key/value pair.
Eg:
- Page begins to load
- JavaScript variable contains something like;
Var FaveFood(['favorite food', 'Hamburger buns'])
- Send key/value 'favorite food', 'Hamburger buns' to Optimizely
- Return an experience for Audiences with a 'favorite food' equal to 'Hamburger buns'
Step 3 is the one I’m trying to work how to do. I know how to do Step 4 via the Optimizely UI, no question there. I’m just trying to find the method to send the key/value pair to Optimziely.
Thanks guys!
Re: Creation of a real time Audience from page level JavaScript variables
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Have a look at this article: https://help.optimizely.com/Target_Your_Visitors/Custom_JavaScript_audience_targeting
According to Optimizely:
If you are using a specific variable defined on your page for Custom JavaScript Targeting, the variable MUST exist on the page ABOVE Optimizely. Otherwise, when Optimizely executes the condition will always evaluate to “false” since the variable or element does not yet exist.
Then in audience conditions, specify custom JavaScript by checking for the existence of your variable. For example, FaveFood.length.


Re: Creation of a real time Audience from page level JavaScript variables
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
I take it that the Optimizely script will read and access any JavaScript variables that are available at the window/document level (technically any JS variable as JS doesn't technically support variable scope like most languages). So long as the variable is declared / lives above the Optimizely embed code it can access the variable.
.. Makes sense. Thank you!