<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<dict>
		<key>Activate</key>
		<string>Normal</string>
		<key>CreationDate</key>
		<real>587629326.39867496</real>
		<key>Macros</key>
		<array>
			<dict>
				<key>Actions</key>
				<array>
					<dict>
						<key>ActionUID</key>
						<integer>4303</integer>
						<key>DisplayKind</key>
						<string>Window</string>
						<key>HonourFailureSettings</key>
						<true/>
						<key>IncludeStdErr</key>
						<false/>
						<key>MacroActionType</key>
						<string>ExecuteJavaScriptForAutomation</string>
						<key>Path</key>
						<string></string>
						<key>Text</key>
						<string>const app = Application.currentApplication()
app.includeStandardAdditions = true


// list source: https://github.com/mpchadwick/tracking-query-params-registry/
const tracking_parameters = [
    "fbclid",       // Facebook
    "igshid",       // Instagram 
    "gclid",        // google adwords/analytics
    "gclsrc",       // google doubleclick
    "utm_name",     // google analytics
    "utm_content",  // google analytics
    "utm_term",     // google analytics
    "utm_campaign", // google analytics
    "utm_medium",   // google analytics
    "utm_source",   // google analytics
    "utm_id",       // google analytics
    "_ga",          // google analytics
    "mc_cid",       // Mailchimp
    "mc_eid",       // Mailchimp
    "_bta_tid",     // Bronto
    "_bta_c",       // Bronto
    "trk_contact",  // Listrak
    "trk_msg",      // Listrak
    "trk_module",   // Listrak
    "trk_sid",      // Listrak
    "gdfms",        // GoDataFeed
    "gdftrk",       // GoDataFeed
    "gdffi",        // GoDataFeed
    "_ke",          // Klaviyo
    "redirect_log_mongo_id",    // Springbot
    "redirect_mongo_id",        // Springbot
    "sb_referer_host",          // Springbot
    "mkwid",        // Marin
    "pcrid",        // Marin
    "ef_id",        // Adobe Ad Cloud
    "s_kwcid",      // Adobe Analytics
    "msclkid",      // Microsoft Ads
    "dm_i",         // dotdigital
    "epik",         // Pinterest
    "pk_campaign",      // Piwik
    "pk_kwd",           // Piwik
    "pk_keyword",       // Piwik
    "piwik_campaign",   // Piwik
    "piwik_kwd",        // Piwik
    "piwik_keyword",    // Piwik
    "mtm_campaign",     // Matomo
    "mtm_keyword",      // Matomo
    "mtm_source",       // Matomo
    "mtm_medium",       // Matomo
    "mtm_content",      // Matomo
    "mtm_cid",          // Matomo
    "mtm_group",        // Matomo
    "mtm_placement",    // Matomo
    "matomo_campaign",  // Matomo
    "matomo_keyword",   // Matomo
    "matomo_source",    // Matomo
    "matomo_medium",    // Matomo
    "matomo_content",   // Matomo
    "matomo_cid",       // Matomo
    "matomo_group",     // Matomo
    "matomo_placement", // Matomo
    "hsa_cam",          // Hubspot
    "hsa_grp",          // Hubspot
    "hsa_mt",           // Hubspot
    "hsa_src",          // Hubspot
    "hsa_ad",           // Hubspot
    "hsa_acc",          // Hubspot
    "hsa_net",          // Hubspot
    "hsa_kw",           // Hubspot
    "hsa_tgt",          // Hubspot
    "hsa_ver"           // Hubspot
]

function detrack(url) {
    let parts = url.split(/\?/,2)
    if (parts.length==1) return url

    let query = parts[1]
    query = query.split('&amp;')
        .filter( param =&gt; {
            let matches = tracking_parameters.filter( q =&gt; (new RegExp(`${q}=`)).test(param) )
            return matches.length==0
        })
        .join('&amp;')
    return query ? `${parts[0]}?${query}` : parts[0]

}


let clip = app.theClipboard()

// only process text 
if (typeof clip != 'string') exit

// process multiple lines
clip = clip.split(/[\r\n]/).map( line =&gt; detrack(line) ).join("\n")

// send back to clipboard
app.setTheClipboardTo(clip)
clip
</string>
						<key>TimeOutAbortsMacro</key>
						<true/>
						<key>TrimResults</key>
						<true/>
						<key>TrimResultsNew</key>
						<true/>
						<key>UseText</key>
						<true/>
					</dict>
				</array>
				<key>CreationDate</key>
				<real>677382192.58271897</real>
				<key>ModificationDate</key>
				<real>677382791.52428806</real>
				<key>Name</key>
				<string>Detracktor</string>
				<key>Triggers</key>
				<array/>
				<key>UID</key>
				<string>7CC73345-BB13-4943-904D-A297545724CA</string>
			</dict>
		</array>
		<key>Name</key>
		<string>Clipboards</string>
		<key>ToggleMacroUID</key>
		<string>D187D943-68DC-4545-8148-51ACF2A3BA43</string>
		<key>UID</key>
		<string>F9227B40-FBCA-45AF-A5B5-88FE21ED26F1</string>
	</dict>
</array>
</plist>