tag
*
* USAGE IN THEME.LIQUID:
*
*
*
* @version 1.0.0
* @date 2026-01-14
* @project Rockwell Growth Marketing - Attribution Fix
*/
(function() {
'use strict';
// Configuration
var UTM_STORAGE_KEY = 'rockwell_utm_data';
var UTM_EXPIRY_HOURS = 24; // How long to keep UTM data in localStorage
// List of parameters to capture
var CAPTURE_PARAMS = [
'utm_source',
'utm_medium',
'utm_campaign',
'utm_content',
'utm_term',
'fbclid', // Meta/Facebook click ID
'gclid', // Google click ID
'ttclid', // TikTok click ID
'msclkid' // Microsoft/Bing click ID
];
/**
* Parse URL parameters
* @returns {Object} Key-value pairs of captured parameters
*/
function getUrlParams() {
var params = {};
try {
var searchParams = new URLSearchParams(window.location.search);
CAPTURE_PARAMS.forEach(function(key) {
var value = searchParams.get(key);
if (value) {
params[key] = value;
}
});
} catch (e) {
// Fallback for older browsers
var queryString = window.location.search.substring(1);
if (queryString) {
queryString.split('&').forEach(function(pair) {
var parts = pair.split('=');
var key = decodeURIComponent(parts[0]);
var value = parts[1] ? decodeURIComponent(parts[1]) : '';
if (CAPTURE_PARAMS.indexOf(key) !== -1 && value) {
params[key] = value;
}
});
}
}
return params;
}
/**
* Store UTM data in sessionStorage (per-tab)
* @param {Object} params - UTM parameters to store
*/
function storeInSession(params) {
try {
Object.keys(params).forEach(function(key) {
sessionStorage.setItem(key, params[key]);
});
// Also store landing page for reference
sessionStorage.setItem('utm_landing_page', window.location.pathname);
sessionStorage.setItem('utm_captured_at', new Date().toISOString());
} catch (e) {
console.warn('[UTM Capture] sessionStorage not available:', e);
}
}
/**
* Store UTM data in localStorage (persists across tabs/sessions)
* @param {Object} params - UTM parameters to store
*/
function storeInLocal(params) {
try {
var data = {
params: params,
landing_page: window.location.pathname,
captured_at: new Date().getTime(),
expires_at: new Date().getTime() + (UTM_EXPIRY_HOURS * 60 * 60 * 1000)
};
localStorage.setItem(UTM_STORAGE_KEY, JSON.stringify(data));
} catch (e) {
console.warn('[UTM Capture] localStorage not available:', e);
}
}
/**
* Get UTM data from localStorage (checks expiry)
* @returns {Object|null} Stored UTM data or null if expired/not found
*/
function getStoredUtm() {
try {
var stored = localStorage.getItem(UTM_STORAGE_KEY);
if (!stored) return null;
var data = JSON.parse(stored);
if (data.expires_at && new Date().getTime() > data.expires_at) {
localStorage.removeItem(UTM_STORAGE_KEY);
return null;
}
return data.params;
} catch (e) {
return null;
}
}
/**
* Main execution
*/
function init() {
var urlParams = getUrlParams();
var hasParams = Object.keys(urlParams).length > 0;
if (hasParams) {
// New UTM parameters detected - store them
storeInSession(urlParams);
storeInLocal(urlParams);
console.log('[UTM Capture] Parameters captured:', Object.keys(urlParams).join(', '));
} else {
// No new params - check if we have stored data to restore to session
var storedParams = getStoredUtm();
if (storedParams && Object.keys(storedParams).length > 0) {
// Restore to session storage for consistency
Object.keys(storedParams).forEach(function(key) {
if (!sessionStorage.getItem(key)) {
sessionStorage.setItem(key, storedParams[key]);
}
});
console.log('[UTM Capture] Restored from localStorage:', Object.keys(storedParams).join(', '));
}
}
}
// Run when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
// Expose utility function for other scripts
window.RockwellUTM = {
getParams: function() {
var params = {};
CAPTURE_PARAMS.forEach(function(key) {
var value = sessionStorage.getItem(key);
if (value) params[key] = value;
});
return params;
},
getStoredParams: getStoredUtm
};
})();
For years, the shaving industry has pushed the idea that “more blades = better shave.” Cartridge razors went from two blades, to three, to five, and now even more. But...
For years, the shaving industry has pushed the idea that “more blades = better shave.” Cartridge razors went from two blades, to three, to five, and now even more. But...
Shaving your head can be liberating - no bad hair days, no constant trims, just a clean and confident look. But if you’ve ever tried shaving your head with a...
Shaving your head can be liberating - no bad hair days, no constant trims, just a clean and confident look. But if you’ve ever tried shaving your head with a...
Finding the right gift for a milestone moment - graduation, a birthday, wedding anniversary, or a “welcome to adulthood” moment, can feel like a lot of pressure. You want something...
Finding the right gift for a milestone moment - graduation, a birthday, wedding anniversary, or a “welcome to adulthood” moment, can feel like a lot of pressure. You want something...
Struggling with razor burn or irritation? Discover why adjustable, single-blade, stainless steel razors like Rockwell are the best choice for sensitive skin.
Struggling with razor burn or irritation? Discover why adjustable, single-blade, stainless steel razors like Rockwell are the best choice for sensitive skin.