How to Detect Traffic Sources and Adapt Content in Webflow
Learn how to detect a visitor’s traffic source and dynamically adapt your Webflow page content.
In this tutorial, Sandro, cofounder of Gemeos Webflow agency, shows you how to detect a visitor’s traffic source and dynamically adapt the content on your Webflow page.
Example
Simulate a traffic source
Source
Detection
Example
utm_source
URL parameter
?utm_source=linkedin
Google
document.referrer
google.com in the referrer
LinkedIn
document.referrer
linkedin.com in the referrer
Direct
Empty referrer
Direct access or bookmark
Meta
data-traffic-source attribute
CSS targeted by source
1. Add the dynamic elements in Webflow
Create a Text Block with the ID source-message for the dynamic message. To show an element only for a specific source, add the custom attribute data-show-source with the value linkedin, google, or meta. Set these elements to display: none by default.
2. Add the script in Footer code
(function() { var params = new URLSearchParams(window.location.search); var ref = document.referrer; var source = params.get('utm_source') || '';
function getSource() { if (source) return source.toLowerCase(); if (ref.includes('linkedin')) return 'linkedin'; if (ref.includes('twitter') || ref.includes('x.com')) return 'twitter'; if (ref.includes('google')) return 'google'; if (ref.includes('facebook') || ref.includes('instagram')) return 'meta'; if (ref === '') return 'direct'; return 'other'; }
var src = getSource(); document.body.setAttribute('data-traffic-source', src);
// Dynamic content based on source var messages = { 'linkedin': 'Welcome from LinkedIn! See how we help B2B teams.', 'google': 'You found us on Google. Here’s what we do.', 'meta': 'Welcome from our ads! Here’s our offer.', 'direct': 'Welcome! Here’s what Gemeos does.', 'other': 'Welcome to Gemeos.' };
var el = document.getElementById('source-message'); if (el) el.textContent = messages[src] || messages['other'];
// Show/hide elements by source document.querySelectorAll('[data-show-source]').forEach(function(el) { var sources = el.dataset.showSource.split(','); el.style.display = sources.indexOf(src) !== -1 ? '' : 'none'; }); })();
3. Source-based CSS customization
The script adds a data-traffic-source attribute to the body. You can target sources in CSS:
/* In a global CSS embed */ [data-traffic-source='linkedin'] .hero-cta { background: #0077b5; } [data-traffic-source='google'] .promo-banner { display: block; }
good to know
document.referrer is empty when a visitor comes from HTTPS to HTTP, from a link in an app (Slack, native email), or directly. The utm_source parameter is more reliable because you control it. Combine both: utm_source first, referrer as a fallback. For email campaigns, always add utm_source=email for reliable detection.
Conclusion
Adapting content to the source improves relevance and conversion rates. Use cases:
Personalized welcome message based on the campaign
Different CTA for LinkedIn vs Google visitors
Special offer visible only from a Meta ad
Source detected in your current session
data-traffic-source :
Detecting...
Good to know
Heading
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.