Skip to content

Commit

Permalink
Merge pull request #48 from hlxsites/main
Browse files Browse the repository at this point in the history
Release 20241107
  • Loading branch information
davenichols-DHLS authored Nov 7, 2024
2 parents bccb84f + 598c7fa commit 405abb5
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 26 deletions.
4 changes: 2 additions & 2 deletions blocks/product-children/product-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getCookie, isOTEnabled,
} from '../../scripts/scripts.js';
import {
getProductResponse, getSKU,
getProductResponse,
} from '../../scripts/commerce.js';

customElements.define('product-tile', ProductTile);
Expand Down Expand Up @@ -88,7 +88,7 @@ const childProducts = `
`;

export default async function decorate(block) {
const sku = getSKU();
const sku = document.querySelector('.sku.hidden')?.textContent.trim();
const host = (window.location.host === 'lifesciences.danaher.com') ? window.location.host : 'stage.lifesciences.danaher.com';
const response = await getProductResponse();
if (response?.length > 0 && response[0]?.raw?.objecttype === 'Family' && response[0]?.raw?.numproducts > 0) {
Expand Down
4 changes: 2 additions & 2 deletions blocks/product-resources/product-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getCookie, isOTEnabled,
} from '../../scripts/scripts.js';
import {
getProductResponse, getSKU,
getProductResponse,
} from '../../scripts/commerce.js';

const productResources = `
Expand Down Expand Up @@ -186,7 +186,7 @@ const productResources = `
`;

export default async function decorate(block) {
const sku = getSKU();
const sku = document.querySelector('.sku.hidden')?.textContent.trim();
const host = (window.location.host === 'lifesciences.danaher.com') ? window.location.host : 'stage.lifesciences.danaher.com';
const response = await getProductResponse();
if (response?.length > 0 && response[0]?.raw?.objecttype === 'Family' && response[0]?.raw?.numresources > 0) {
Expand Down
20 changes: 16 additions & 4 deletions scripts/commerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,25 @@ export function getCommerceBase() {
*/
export function getAuthorization() {
const authHeader = new Headers();
const siteID = window.DanaherConfig?.siteID;
const hostName = window.location.hostname;
let env;
if (hostName.includes('local')) {
env = 'local';
} else if (hostName.includes('dev')) {
env = 'dev';
} else if (hostName.includes('stage')) {
env = 'stage';
} else {
env = 'prod';
}
if (localStorage.getItem('authToken')) {
authHeader.append('Authorization', `Bearer ${localStorage.getItem('authToken')}`);
} else if (getCookie('ProfileData')) {
const { customer_token: apiToken } = getCookie('ProfileData');
authHeader.append('authentication-token', apiToken);
} else if (getCookie('apiToken')) {
const apiToken = getCookie('apiToken');
} else if (getCookie(`${siteID}_${env}_apiToken`)) {
const apiToken = getCookie(`${siteID}_${env}_apiToken`);
authHeader.append('authentication-token', apiToken);
}
return authHeader;
Expand Down Expand Up @@ -85,8 +97,8 @@ export async function getProductResponse() {

const host = `https://${window.DanaherConfig.host}/us/en/product-data`;
const url = window.location.search
? `${host}/${window.location.search}&aq=@productid==${sku}`
: `${host}/?aq=@productid==${sku}`;
? `${host}/${window.location.search}&product=${sku}`
: `${host}/?product=${sku}`;

const fullResponse = await fetch(url)
.then((res) => {
Expand Down
56 changes: 41 additions & 15 deletions scripts/delayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ function loadGTM() {
}
// google tag manager -end

// SalesForce MCP - start

function loadEvergageScript() {
const script = document.createElement('script');
if (window.location.host === 'lifesciences.danaher.com') {
script.src = 'https://cdn.evgnet.com/beacon/v55685555553mx3rf3h3n3n3i091550196/danaher_ls_prod/scripts/evergage.min.js';
} else {
script.src = 'https://cdn.evgnet.com/beacon/v55685555553mx3rf3h3n3n3i091550196/danaher_ls_staging/scripts/evergage.min.js';
}
script.onload = function onEvergageLoad() {
};
script.onerror = function onEvergageError() {
};
document.head.appendChild(script);
}

/* eslint-disable no-console */
if (typeof OnetrustActiveGroups !== 'undefined' && OnetrustActiveGroups.includes("C0004")) {
loadEvergageScript();
}

// SalesForce MCP - end

// Adobe Target - start

window.targetGlobalSettings = {
Expand All @@ -59,14 +82,14 @@ function sendCoveoEventPage() {
const pdftitle = usp.get('title');

let cval = '';
if( pdfurl != null && pdfurl.length > 0){
if (pdfurl != null && pdfurl.length > 0) {
cval = window.location.origin + pdfurl;
} else {
cval = window.location.origin + window.location.pathname;
}

let title = '';
if( pdftitle != null && pdftitle.length > 0 ){
if (pdftitle != null && pdftitle.length > 0) {
title = pdftitle;
} else {
title = document.title;
Expand All @@ -77,7 +100,7 @@ function sendCoveoEventPage() {
accessToken,
`https://${organizationId}.analytics.org.coveo.com`,
);

coveoua('send', 'view', {
contentIdKey: 'permanentid',
contentIdValue: cval,
Expand All @@ -86,7 +109,7 @@ function sendCoveoEventPage() {
title: title,
location: document.location.href,
originLevel1: "DanaherMainSearch",
});
});
}

function sendCoveoEventProduct() {
Expand All @@ -100,19 +123,19 @@ function sendCoveoEventProduct() {

const cats = document.querySelector('.hero-default-content .categories');
let pcats = '';
if( cats != null ){
if (cats != null) {
pcats = cats.textContent.replaceAll('|', '/').replaceAll(',', '|');
}

coveoua('ec:addProduct', {
id: document.querySelector('.hero-default-content .sku')?.textContent,
id: document.querySelector('.hero-default-content .sku')?.textContent,
name: document.querySelector('.hero-default-content .title')?.textContent,
category: pcats,
price: 0,
brand: document.querySelector('.hero-default-content .brand')?.textContent
});

coveoua('ec:setAction', 'detail');
coveoua('ec:setAction', 'detail');
coveoua('send', 'event', {
"searchHub": "DanaherMainSearch"
});
Expand All @@ -131,10 +154,13 @@ async function getAuthToken() {
body: formData,
});
if (authRequest.ok) {
const siteID = window.DanaherConfig?.siteID;
const hostName = window.location.hostname;
const env = hostName.includes('local') ? 'local' : hostName.includes('dev') ? 'dev' : hostName.includes('stage') ? 'stage' : 'prod';
const data = await authRequest.json();
const expiresIn = data.expires_in * 1000;
setCookie('apiToken', data.access_token, expiresIn, '/');
localStorage.setItem('refreshToken', data.refresh_token);
setCookie(`${siteID}_${env}_apiToken`, data.access_token, expiresIn, '/');
localStorage.setItem(`${siteID}_${env}_refresh-token`, data.refresh_token);
}
}
}
Expand All @@ -149,9 +175,9 @@ loadScript('https://cdn.usefathom.com/script.js', attrs);
(function (c, o, v, e, O, u, a) {
a = 'coveoua';
c[a] = c[a]
|| function () {
(c[a].q = c[a].q || []).push(arguments);
};
|| function () {
(c[a].q = c[a].q || []).push(arguments);
};
c[a].t = Date.now();

u = o.createElement(v);
Expand Down Expand Up @@ -183,10 +209,10 @@ if (!window.location.hostname.includes('localhost')) {
loadGTM();
//loadAT();

if (isOTEnabled()){
if (getMetadata('template') === 'ProductDetail' && document.querySelector('h1') ) {
if (isOTEnabled()) {
if (getMetadata('template') === 'ProductDetail' && document.querySelector('h1')) {
sendCoveoEventProduct();
} else if(getMetadata('template') !== 'ProductDetail'){
} else if (getMetadata('template') !== 'ProductDetail') {
sendCoveoEventPage();
}
}
Expand Down
2 changes: 0 additions & 2 deletions styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,6 @@ main .section:not(.stretch, .product-hero-container, .workflow-carousel-containe
font-size: 1.25rem !important;
line-height: 1.75rem !important;
font-weight: 700;
--tw-text-opacity: 1;
color: rgb(17 24 39 / var(--tw-text-opacity));
}

.container-two-col .col-right ul, .accordion-answer ul {
Expand Down
2 changes: 1 addition & 1 deletion styles/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
}

.container-two-col .col-right h2 {
@apply inline-flex mb-2 font-semibold !text-xl text-danahergray-900;
@apply inline-flex mb-2 font-semibold !text-xl;
}

.container-two-col .col-right ul, .accordion-answer ul {
Expand Down

0 comments on commit 405abb5

Please sign in to comment.