@networkpro/web
Version:
Locking Down Networks, Unlocking Confidence™ | Security, Networking, Privacy — Network Pro Strategies
28 lines (23 loc) • 863 B
JavaScript
/* ==========================================================================
src/lib/utils/utm.js
Copyright © 2025 Network Pro Strategies (Network Pro™)
SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
This file is part of Network Pro.
========================================================================== */
/**
* @file utm.js
* @description Append UTM parameter from window.location to a given URL.
* @module src/lib/utils/
* @author SunDevil311
* @updated 2025-05-28
*/
/**
* Returns `null` if not in a browser context.
* @param {string} url - The base URL to append to
* @returns {string | null}
*/
export function appendUTM(url) {
if (typeof window === 'undefined') return null;
const utm = new URLSearchParams(window.location.search).get('utm_source');
return utm ? `${url}?utm_source=${encodeURIComponent(utm)}` : url;
}