Tracking4 min read
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 |
| document.referrer | google.com in the referrer | |
| 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; }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...


