The paradoxical impact of adding tools to a website is reminiscent of a well-known phenomenon in science: The Observer Effect. The Observer Effect means the act of observing a system will influence what is being observed Just as the act of observing can inadvertently alter the results of an experiment, incorporating tools intended to optimize a website can sometimes have unintended consequences, such as slower loading times and diminished user experience.
Website owners must navigate this delicate balance, carefully evaluating the necessity and impact of each tool they consider implementing. By prioritizing essential tools, regularly monitoring performance, and employing best practices, they can harness the benefits of optimization while minimizing potential drawbacks.
Ultimately, striking the right balance between optimization and user experience is crucial for creating a successful website that engages and retains visitors. By being mindful of the observer effect in web development, site owners can make informed decisions that lead to better outcomes for their website and users.
Visitor Sampling
I have Martech Zone integrated with Microsoft Clarity so that I can observe sessions and capture unique user behaviors. This has led to several improvements in my site layout (with more coming), and I’m appreciative of the tool. However, loading the tool on every visit simultaneously slows my site down. It’s not an enormous difference, but it’s unnecessary for every visit. All I need is a sampling of my users.
Using a sample size calculation, I can have a 95% assurance rate with approximately 774 sessions of my 60,000 monthly users. So… why not just have the tag executed once every 1,000 visits to get a random sampling of my overall visits? I started to wonder if I could do this within our tag management system (TMS), Google Tag Manager (GTM), and it’s possible!
Google Tag Manager Sampling
This solution uses Google Tag Manager to implement sampling, allowing you to collect data from a representative portion of your website visitors instead of tracking every single visitor. The business can control the percentage of visitors whose actions are recorded and analyzed by setting up a Custom JavaScript Variable and a Trigger in Google Tag Manager.
A Custom JavaScript Variable uses a simple mathematical function to randomly select approximately 1 out of every 1000 visitors (or any other desired ratio). When a visitor loads a page or performs an action that meets the Trigger conditions, the Variable is evaluated. If the visitor is part of the randomly selected sample, the associated Tag is fired, and their data is collected.
How to Implement Sampling
Here’s a step-by-step guide to implementing the sampling solution in Google Tag Manager, along with an explanation of the code:
- Create a new Custom JavaScript Variable:
- In your Google Tag Manager container, navigate to Variables
- Under User-Defined Variables, click New
- Name the variable, e.g., Every 1000
- In the Variable Configuration section, select Custom JavaScript as the variable type
- In the code editor, enter the following code and save the variable:
function() {
return Math.floor(Math.random() * 1000) === 0;
}
Code Explanation:
Math.random()
generates a random number between 0 and 1 (exclusive)* 1000
scales the random number to a range between 0 and 999 (inclusive)Math.floor()
rounds down the scaled random number to the nearest integer=== 0
checks if the rounded number is equal to 0 (which will be true for approximately 1 out of every 1000 visitors)- True or false is returned.
- Create a new Trigger:
- In your Google Tag Manager container, navigate to Triggers
- Click New to create a new trigger
- Name the trigger, e.g., 1000 Views
- Choose the trigger type based on Page Views.
- Under This trigger fires on, select Some Pages.
- In the condition field, select the Every 1000 you created earlier
- Set the condition to equals and enter true
- Save the trigger
- Assign the Trigger to the desired Tag:
- In your Google Tag Manager container, navigate to Tags
- Select the tag you want to apply the sampling to, or create a new tag
- Under Triggering, click the + icon to add a trigger
- Select the 1000 Views you created in step 2
- Save the tag
- Preview and Publish:
- Click Preview in the top right corner of the Google Tag Manager interface to enter preview mode
- Open your website in a new browser tab and navigate to a page where the tag should fire
- Check the Google Tag Manager preview panel to ensure that the tag fires only for the sampled visitors
- If everything works as expected, click Submit in the Google Tag Manager interface to publish your changes
The tag will only fire for approximately 1 out of every 1000 visitors (0.1% of your traffic) who meet the trigger conditions. As explained above, you can adjust the sampling rate by modifying the number in the Custom JavaScript Variable.
This sampling method helps businesses manage the volume of data they collect and process, which can reduce costs and improve data processing times. Remember to thoroughly test your implementation and consider the potential impact of sampling on your data accuracy before deploying the changes to your live environment.
Sampling can balance the need for comprehensive data with the practicalities of managing large volumes of information. This approach allows them to gather valuable insights while optimizing your resources and maintaining a streamlined data collection process.
Remember that this need not be limited to loading an analytics tag. Sampling can be based on clicks, used for A/B testing an external popup script, or provide other opportunities!