Skip to content

Instantly share code, notes, and snippets.

@omrilotan
Created April 5, 2020 14:09
Show Gist options
  • Save omrilotan/f2b8b0e5633529858cee492b1eee199d to your computer and use it in GitHub Desktop.
Save omrilotan/f2b8b0e5633529858cee492b1eee199d to your computer and use it in GitHub Desktop.
const providers = [
['googletagmanager.com', 'googletagmanager'],
['linkedin.com', 'linkedin'],
['d2c7xlmseob604.cloudfront.net', 'smartling'],
['d2fltix0v2e0sb.cloudfront.net', 'dev.to'],
];
/**
* Get the name of the script provider where applicable
* @param {string} url
* @return {string|undefined}
*/
function thirdPartyProvider(url) {
const { hostname } = new URL(url);
return (
providers.find(
([domain]) => hostname.endsWith(domain)
) || []
)[1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment