Auto-Populate Source/Medium Documentation
Auto-Populate Source/Medium Documentation
Overview
The Auto-Populate Source/Medium feature automatically sets utm_source and utm_medium parameters based on the detected traffic source and organic source string. This is particularly useful for tracking organic and referral traffic without manually setting UTM parameters.
How It Works
Server-Side Tracking
Reference to implementation:
function handl_auto_populate_source_medium() {
if (get_option('handl_auto_populate_source_medium') !== '1') {
return;
}
$traffic_source = isset($_COOKIE['traffic_source']) ? $_COOKIE['traffic_source'] : '';
$organic_source = isset($_COOKIE['organic_source_str']) ? $_COOKIE['organic_source_str'] : '';
if (!empty($traffic_source) && !isset($_COOKIE['utm_source'])) {
HandLCreateParameters('utm_source', $traffic_source, getDomainName());
}
if (!empty($organic_source) && !isset($_COOKIE['utm_medium'])) {
HandLCreateParameters('utm_medium', $organic_source, getDomainName());
}
}
When enabled, the plugin will:
Set utm_source to the value of traffic_source cookie
Set utm_medium to the value of organic_source_str cookie
Client-Side Tracking
Reference to traffic source detection:
let traffic_source = 'Other'
if (
Object.keys(qvars).indexOf('fbclid') != -1 ||
Object.keys(qvars).indexOf('gclid') != -1 ||
Object.keys(qvars).indexOf('msclkid') != -1
){
traffic_source = 'Paid'
}else if ( ['Google','Bing','Yahoo','Duckduckgo'].indexOf(Cookies.get('organic_source_str')) > -1 ){
traffic_source = 'Organic'
}else if ( ['Facebook','Twitter','Instagram','Snapchat','YouTube','Pinterest','LinkedIn','Tumblr'].indexOf(Cookies.get('organic_source_str')) > -1 ){
traffic_source = 'Social'
}else if ( ['Internal','Direct'].indexOf(Cookies.get('organic_source_str')) > -1 ){
traffic_source = 'Direct'
traffic_source = 'Referral'
}
The traffic source is determined as follows:
Paid: When fbclid, gclid, or msclkid parameters are present
Organic: Traffic from search engines (Google, Bing, Yahoo, DuckDuckGo)
Direct: When no referrer is present or internal traffic
Referral: All other external traffic sources
Configuration
Admin Settings
The feature can be enabled/disabled through the HandL UTM Grabber settings page under the "Options" tab.
Settings include:
Checkbox to enable/disable auto-population
Description explaining the functionality
Integration with existing UTM tracking
Value Mapping
Traffic sources are mapped as follows:
utm_source will be set to one of:
Paid
Organic
Direct
Referral
Other
utm_medium will be set to the specific source:
Bing
Yahoo
Direct
Internal
etc.
Usage Examples
Tracking Organic Search Traffic
When a visitor comes from Google search:
utm_source = "Organic"
utm_medium = "Google"
Tracking Social Media Traffic
When a visitor comes from Facebook:
utm_medium = "Facebook"
Tracking Referral Traffic
When a visitor comes from a blog that linked to your site:
utm_source = "Referral"
utm_medium = [referring domain]
Integration with Other Features
The auto-populate feature integrates with:
Form submissions (Reference: premiums/formSubmitHandles.php)
WooCommerce tracking (Reference: premiums/woocommerce.php)
WordPress comments (Reference: premiums/WPcommentUTM.php)
Important Notes
The feature only sets UTM parameters if they're not already present
Values are stored in cookies for consistent tracking across sessions
Respects GDPR settings and cookie consent
Works with both server-side and client-side tracking
Compatible with the plugin's custom parameter feature
Technical Requirements
WordPress 4.0 or higher
HandL UTM Grabber v3.0 or higher
JavaScript enabled in the browser
Troubleshooting
If UTM parameters are not being set:
Verify the feature is enabled in settings
Ensure server-side tracking is not disabled
Verify no conflicting UTM parameters are present in URLs