- Help Center
- Configuration
- Targeting
-
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
Tracking visitors until they see the element being tested in the page
THIS ARTICLE WILL HELP YOU:
Description
Sometimes an optimizer might be concerned with only measuring visitors that see the element being changed in the test, as bucketing all visitors that land on the page, might cause a degree of noise in the sample of visitors bucketed and measured in the test.
Solution
To aid in excluding the visitors that do not see the elements changed on the page, the following solution has been put together. This configuration will only bucket visitors in the experiment that see an element on the page, which should be the one that is being tested.
- First, find the selector for the element that you are changing. You might find it on the variation code for the experiment you are carrying on, or you might find that manually using the process described in this article.
- Add the following code to your Project Configuration> Global Javascript.
// This extends jquery to return true when an element is viewed on the page:
convert.$.fn.isInViewport = function() {
var elementTop = convert.$(this).offset().top;
var elementBottom = elementTop + convert.$(this).outerHeight();
var viewportTop = convert.$(window).scrollTop();
var viewportBottom = viewportTop + convert.$(window).height();
return elementBottom > viewportTop && elementTop < viewportBottom;
};
// This queries the last function every time there is a window scroll and resize, checking
// if the element is on view.
convert.$(window).on('resize scroll', function() {
// MODIFY THE H2 WITH YOUR OWN SELECTOR
if (convert.$('H2').isInViewport()){
// If in view run the experiment
// MODIFY THE FOLLOWING LINE WITH THE ID OF YOUR EXPERIMENT:
window.runExperiment123456789 = 1;
window._conv_q = window._conv_q || [];
window._conv_q.push(["executeExperiment","100123828"])
}
}); - Modify the code above with the selector and the runExperiment123456789 variable, modified with your experiment id.
- Add a JS Condition in the Audience as a Custom Audience that evaluates the variable that you just modified with your own experiment id, like:
window.runExperiment123456789 == 1
- Congratulation. You are done. Your experiment will only bucket the visitors of the page that see the element changed on the page.
keywords: on view, increase accuracy