Skip to content

Commit

Permalink
Merge pull request #196 from hlxsites/86-analytics
Browse files Browse the repository at this point in the history
86 analytics
  • Loading branch information
rrusher authored Feb 6, 2024
2 parents 6eab3e1 + 56140b7 commit df20239
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
17 changes: 15 additions & 2 deletions scripts/delayed.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
// eslint-disable-next-line import/no-cycle
import { sampleRUM } from './aem.js';
import { sampleRUM, loadScript } from './aem.js';
import { getEnvType } from './util.js';

// Core Web Vitals RUM collection
sampleRUM('cwv');

// add more delayed functionality here
async function loadAdobeLaunch() {
const adobedtmSrc = {
dev: 'https://assets.adobedtm.com/2079c5a4620d/addee6043c9b/launch-EN41458ac9f88145ac942b876e3362c32f-development.min.js',
preview: 'https://assets.adobedtm.com/2079c5a4620d/addee6043c9b/launch-EN367ab3c0970e43a0afba6d1110494ef4-staging.min.js',
live: 'https://assets.adobedtm.com/2079c5a4620d/addee6043c9b/launch-EN8919423a46da4e859aad8cef6f514471.min.js',
};
await loadScript(adobedtmSrc[getEnvType()], {
type: 'text/javascript',
async: true,
});
}

if (!window.location.host.includes('localhost')) await loadAdobeLaunch();
16 changes: 16 additions & 0 deletions scripts/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,26 @@ export async function i18nLookup(prefix) {
};
}

/*
* Returns the environment type based on the hostname.
*/
export function getEnvType(hostname = window.location.hostname) {
const fqdnToEnvType = {
'commonmoves.com': 'live',
'www.commonmoves.com': 'live',
'stage.commonmoves.com': 'preview',
'preview.commonmoves.com': 'preview',
'main--hsf-commonmoves--hlxsites.hlx.page': 'dev',
'main--hsf-commonmoves--hlxsites.hlx.live': 'dev',
};
return fqdnToEnvType[hostname] || 'dev';
}

const Util = {
getSpinner,
showModal,
i18nLookup,
getEnvType,
};

export default Util;

0 comments on commit df20239

Please sign in to comment.