- Help Center
- Developers
-
Getting Started
-
Configuration
- Targeting
- Split URL
- Product Testing
- Full Stack
- Experiment Management
- CSP Configuration
- Experiment Execution
- Reports
- Exit Popups
- GTM Integration
- Troubleshooting
- Performance Optimization
- Event-Triggered Changes
- Holdout Groups
- Split URL Pages
- URL Parameters
- DataLayer
- Menu Configurations
- Traffic Exclusion
- Experiment Scheduling
- Dynamic Element Changes
- Price Targeting
- Experience Scheduling
- Privacy
- Hash Changes
- Async Tracking
- Selective Installation
- CSS Selectors
- Vue.js Integration
- Page Content
- Multipage Split URL
- Organic Traffic
- Visual Editor
- Server-Side Testing
- Traffic Bucketing
- GDPR Warnings
- Statistical Confidence
- Browser Privacy
- Query Parameters
- Embedded Videos
- Tracking Code Execution
- Simultaneous Experiments
- Tags
- Deployments
- Disable Testing
- Locations
- Programmatic Bucketting
- Query Parameter Handling
- Convert Library
- Variation Previews
- Experiment Editing
- Opt-Out Script
- Data Reset
- Body Hiding
- Visit-Specific Variations
- Variation Styling
- Preview Issues
- Variation Editing
- Full-Site Testing
- Blinking Variations
- Cross-Domain Cookies
- Regex Support
- Conversion Tracking
- SPA Testing
- Project Setup
- Cross-Domain Tracking
- Geo-Targeting
- Analytics Tools
- Campaign Tags
- Previewing
- IDs
- Query String Targeting
- Bounce Rate Goals
- Bot Filtering
- Query String Variables
- Custom Audiences
- Redirects
- Baseline
- Tracking Code Location
- Secure Cookies
- AngularJS
- Cloudflare
- Code Installation
-
Track Goals
- Form Tracking
- Cookie Management
- iFrame Click Tracking
- Performance Optimization
- Revenue Tracking
- Interaction Goals
- Form Submissions
- Advanced Goals
- Lazy Loading
- Multi-Conversions
- URL Parameters
- Bounce Rate Goals
- DataLayer Integration
- Scroll Depth
- Social Interactions
- Page Views
- Marketo Forms
- Feature Analysis
- AJAX Forms
- Revenue Tracking via GTM
- Order Outliers
- Cumulative Revenue
- Goal Templates
- Adding Revenue Goals
- JS-Based Goals
- Goal Basics
- Google Analytics Goals
- Social Sharing
- Dynamic Goals
- Typeform Integration
-
Target Visitors
- Geolocation
- Interaction Goals
- Goal-Based Targeting
- Weather Targeting
- Cookie-Based Targeting
- Page Visits
- Audience Management
- Audience Segmentation
- Experiment Targeting
- Advanced Audience Creation
- Audience Templates
- Audience Creation
- Data Layer Integration
- Manual Activation
- JavaScript Conditions
- Device Targeting
- Language Targeting
- IP-Based Exclusion
- Visitor Management
- Page Tagging
- Cookies
-
Troubleshooting
- Google Warnings
- Visual Editor
- HTTPS Content
- Logs
- Support Options
- Bootstrap
- Cookie Blocking
- Change History
- Mobile Debugging
- AdWords
- Bot Exclusion
- Domain Issues
- Cloudflare Issues
- Monitoring
- Cloaking Penalties
- Goal Editor Issues
- Variations
- Snippet Performance
- Changes Not Saved
- Blocked Visual Editor
- Goal Testing
- Visual Editor Browsing
- Experiment Issues
- Installation Verification
- Data Leak Prevention
- Usage Limits
- Experiment Previews
- GA4 Revenue
- Chrome Debugger Logs
- SPA Errors
- Checkout JSON Error
-
Analyze Results
-
Integrations
- Google Analytics
- Cookie Consent Platforms
- Microsoft Clarity
- Plausible
- Marketo
- HubSpot
- Tealium
- Smartlook
- Klaviyo
- Salesforce CRM
- FullStory
- Snowplow Analytics
- Webflow
- GA4 Roles
- Amplitude
- Segment
- React
- BigCommerce
- WooCommerce
- Active Campaign
- Google Tag Manager
- Mixpanel
- Zapier
- Inspectlet
- Crazy Egg
- LanderApp
- Unbounce
- Instapage
- Drupal
- PrestaShop
- Magento
- Roistat
- Piano Analytics
- Heap Analytics
- Kissmetrics
- Mouseflow
- Adobe Analytics
- Clicky
-
Account Management
-
Developers
-
What's New
-
Common Questions
-
Shopify
Experiment Life cycle Events: Executing Code after an variation has been decided, experiment executed, or goal triggered
This Article Will Help You:
- Issue
- Solution
- experience.variation_decided
- experience.activated
- goal.triggered
- snippet.experiences_evaluated
- snippet.goals_evaluated
- cookies.saved
- snippet.goals_evaluated
- location.triggered
- Sending a Convert Goal conversion to another platform:
Issue
There are times we may need to execute code after an experiment variation has been decided, an experiment executed or a goal triggered. Executing code after these events occur is helpful to be able to send experiment data to third-party analytics platforms and other situations.
Solution
We have launched javascript events to address these situations. Here you can have how they can be triggered:
- experience.variation_decided - gets called each time a variation is being returned in order to be executed
- experience.activated - run each time an experience is activated, after the experience changes have been triggered (aka code ran)
- goal.triggered - executed each time a goal is fired ( a goal is fired only if it needs to be marked as triggered for a running experience)
- snippet.experiences_evaluated - executed after all the experiences have been evaluated on page in order to decide if they are to be presented or not
- snippet.goals_evaluated - executed after all the goals have been evaluated
- cookies.saved - executed each time after convert tracking cookies are saved into browser
- location.triggered - executed after a location conditions are matched
To attach a listener, function to an event, the following is the structure:
_conv_q = window._conv_q || [];
_conv_q.push({
what: 'addListener',
params: {
event: 'experience.variation_decided',
handler: (event) => console.log(JSON.stringify(event))
}
})
- The params.event needs to be one of experience.variation_decided, experience.activated, goal.triggered, snippet.experiences_evaluated or snippet.goals_evaluated
- The params.handler needs to be a function that receives as a parameter the event when it's called.
The parameter received by the handler has the following structure, for each of the possible events:
-
experience.variation_decided
{
"data":{
"experience_id":"111111",
"variation_id":"22222",
"experience_name":"name here",
"variation_name":"name here"
},
"event":"experience.variation_decided"
} -
experience.activated
{
"data":{
"experience_id":"111111",
"variation_id":"22222",
"activated_first_time":false,
"experience_name":"name here",
"variation_name":"name here"
},
"event":"experience.activated"
}activated_first_time - is a boolean which is true if that experiment was now activated for the first time for that visitor.
-
goal.triggered
{
"data":{
"experience_id":"11111",
"variation_id":"222222",
"goal_id":"33333",
"experience_name":"name",
"variation_name":"name"
},
"event":"goal.triggered"
} -
snippet.experiences_evaluated
{
"data":{
},
"event":"snippet.experiences_evaluated"
} -
snippet.goals_evaluated
{
"data":{
},
"event":"snippet.goals_evaluated"
} -
cookies.saved
{
"data":{
},
"event":"cookies.saved"
} -
snippet.goals_evaluated
{
"data":{
},
"event":"snippet.goals_evaluated"
} -
location.triggered
{
"data":{
"experience_id":"111111",
"location_id":"22222",
"location_name":"name here"
},
"event":"location.triggered"
}
Sending a Convert Goal conversion to another platform:
function sendGoal(event){
// Change the goal id to the goal id you want to track
if (event.goal-id == '3333'){
// Use the following if you would like to not send anything else but the event
dataLayer.push({'event':'name_of_event','conversionValue':25});
// Use the following if you wold like to send some additional info attached to the event
//dataLayer.push({'event':name_of_event','goalinfo':JSON.stringify(event)});
}
}
_conv_q = window._conv_q || [];
_conv_q.push({
what: 'addListener',
params: {
event: 'goal.triggered',
handler: (event) => sendGoal(event)
}
})
Important
You must have the Data Anonymization setting disabled on the Project Configuration to be able to read the experiment or variation name from these functions.
keywords: lifecycle events