Let’s Get You Back on Track
Here are some popular links that may help.
<script>
// Change: Added "Thinking..." loader with spinning icon and animated dots to the AI Overview loading state (May 2026)
function enableAIOverview(dataSource) {
let query, url, answer, transactionID;
const LINK_COLOR = '#0662BB';
const checkInterval = setInterval(() => {
const container = document.querySelector('.search-result-container');
if (!container) return;
if (document.querySelector('#ai-overview-block')) {
clearInterval(checkInterval);
return;
}
// if (localStorage.getItem('watson_da') === 'true' && localStorage.getItem('enable_incomprehension') === 'true' && `${window.utag_data.page_language}_${window.utag_data.page_country_code}` === 'en_US') {
const aiOverviewDiv = document.createElement('div');
aiOverviewDiv.id = 'ai-overview-block';
aiOverviewDiv.style.display = 'none';
aiOverviewDiv.style.boxSizing = 'border-box';
aiOverviewDiv.style.padding = '0';
aiOverviewDiv.style.marginBottom = '0';
aiOverviewDiv.style.marginTop = '8px';
aiOverviewDiv.innerHTML = `<div class="ai-shimmer" style="display: none;"><div class="ai-thinking" style="display: flex; align-items: center; margin-bottom: 16px;"><svg class="ai-thinking-icon" width="20" height="20" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><rect width="24" height="24" fill="url(#pattern0_thinking)" /><defs><pattern id="pattern0_thinking" patternContentUnits="objectBoundingBox" width="1" height="1"><use xlink:href="#image0_thinking" transform="scale(0.015625)" /></pattern><image id="image0_thinking" width="64" height="64" preserveAspectRatio="none" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAABQNJREFUeJzt222MnFUVB/Dfnd0F24UKQU0oEKokaPmAGjGhO7smCwkJWIJJgxZbPpSXVLQ2okBf+NIPKkYsJARCaEwQrN22pBJJJFkS6cvObiFsQhoISGKMJtqaqFEbapfuy/HDDu12KbMz8zwznZH9f5mZ+/K/55w5z51zzz3DP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7YJb5+hZ1LBfVnpo3Raur1uNMwAqd+EgofP0PVC1gAnhl2Bp2OvC7Lw0OizwAkD+Mes1idzYF6NBbqsyErUUAOUqzR2zWj6q8NezsIZoxYK357+4AcR2XRoxmlw+8l34Vfp6yYzsY35Hj4FkqVKFeqGqkB7XY8Pu04YdKpMjozxRHPyAWEAhzIpP+Rm4XmnKw/nmTIYI3rq4W1eiUzB5anXaM1zqy+ROWG6ROaRliuRqRUxqsuYGyWry5Vi58w56RSOYY/wS71enuv6fLY7tQaOuVSnleVLllqUh27comDCkENU9oaW9ID3Ea9YZNwayf2qS79PF0p2GEg9jlezRksb4H3EiAXCU8LtFYY9bNzm/6tS2dmIYT8RNnyww7rU54l6ONvLAKFg2AtmZp2Sbalobb2cbXUvkJIpYT0n3fyoKRuzcLaVASjnGpTLY5Ins/xbhDY0AJjyCxCtkVRpOj7yf5ubxzzmkRv+ByZjcDylI8z/AAAAAElFTkSuQmCC" /></defs></svg><span class="ai-thinking-text" style="margin-left: 10px; font-size: 16px; font-weight: 500; color: #333;">Thinking</span></div><div class="shimmer-line" style="width: 80%; height: 16px; margin-bottom: 10px;"></div><div class="shimmer-line" style="width: 60%; height: 16px;"></div></div><div class="ai-overview-content" style="overflow-wrap: anywhere; word-break: normal; transition: opacity 1s ease;"><div style="background-color: #FFFFFF; border-radius: 10px; margin-bottom: 0; padding: 20px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.05);"><div style="display: flex; align-items: center; margin-bottom: 17px;"><svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><rect width="24" height="24" fill="url(#pattern0_5_943)" /><defs><pattern id="pattern0_5_943" patternContentUnits="objectBoundingBox" width="1" height="1"><use xlink:href="#image0_5_943" transform="scale(0.015625)" /></pattern><image id="image0_5_943" width="64" height="64" preserveAspectRatio="none" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAAC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VRSb8WLgVFzZCiCowgZckP6znzF8JrZkSayLmH4F6JpUfizuFdbgsZ5mO4xnJE1kSHdUi28/giAWm3IsH5eMRuyQbUtGfc+CqCrmcBeKgpSYN4PN1Uvwba1Ov3XnIUwtyOwyVr692qz0aPCLceLYORbmeBstJkF/j5iqnHNah2MzIbzbyPw5Pe8I+fHmOoe8q6GlGtFcJuccB6Rr/FVbiaOWB1p9t5WlQIJT6/FHY9KEDwmAqeroRa9eKxkWCE7YJb5+hZ1LBfVnpo3Raur1uNMwAqd+EgofP0PVC1gAnhl2Bp2OvC7Lw0OizwAkD+Mes1idzYF6NBbqsyErUUAOUqzR2zWj6q8NezsIZoxYK357+4AcR2XRoxmlw+8l34Vfp6yYzsY35Hj4FkqVKFeqGqkB7XY8Pu04YdKpMjozxRHPyAWEAhzIpP+Rm4XmnKw/nmTIYI3rq4W1eiUzB5anXaM1zqy+ROWG6ROaRliuRqRUxqsuYGyWry5Vi58w56RSOYY/wS71enuv6fLY7tQaOuVSnleVLllqUh27comDCkENU9oaW9ID3Ea9YZNwayf2qS79PF0p2GEg9jlezRksb4H3EiAXCU8LtFYY9bNzm/6tS2dmIYT8RNnyww7rU54l6ONvLAKFg2AtmZp2Sbalobb2cbXUvkJIpYT0n3fyoKRuzcLaVASjnGpTLY5Ins/xbhDY0AJjyCxCtkVRpOj7yf5ubxzzmkRv+ByZjcDylI8z/AAAAAElFTkSuQmCC" /></defs></svg><h2 style="margin: 0 0 0 10px; font-size: 20px; font-weight: 500; line-height: 28px;">AI Overview <sup style="color: #121212; font-size: 10px; font-style: italic; font-weight: 700;">BETA</sup></h2></div><p class="aisummary" style="font-weight: 400; font-size: 16px;">Tracking your UPS package will show you the most up-to-date information on your delivery's whereabouts. Looks like our first delivery or pickup attempt was unsuccessful. Your driver left a delivery notice to let you know that was their first attempt. Check the boxes on the delivery notice. They'll tell you the status of your shipment and if we're able to try delivering or picking up again.</p><a href="#" class="summary-toggle" style="display: none; color: #0662BB; font-size: 16px;">See more</a><div class="linksource_text">Find out more here:</div><ul class="link-list"></ul><div class="toggle-container"></div><div class="ai_footer"><div class="disclaimer" style="flex:1;"><p>This content is generated with the assistance of AI and may contain errors.</p><p>For more information, please review the <a href="https://www.ups.com/us/en/support/shipping-support/legal-terms-conditions/privacy-notice" target="_blank">UPS Privacy Notice</a>.</p></div><div class="feedback"><div class="feedback_text">Your feedback helps us improve and refine our results.</div><div class="feedback_buttons"><button id="thumbs-up" aria-label="Thumbs up"><svg id="thumb-up-svg" width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="64" height="64"><path id="thumb-up-path" d="M1 21h4V9H1v12zM23 10.998c0-.799-.316-1.519-.879-2.062a2.982 2.982 0 0 0-2.221-.938h-6.31l.95-4.57.03-.33a1 1 0 0 0-.29-.7L13 2 6.59 8.41A2.006 2.006 0 0 0 6 9.83V19a2 2 0 0 0 2 2h9c.83 0 1.6-.4 2.09-1.09l3-4.294a3.014 3.014 0 0 0 .91-2.743z" /></svg></button><button id="thumbs-down" aria-label="Thumbs down"><svg id="thumb-down-svg" width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="64" height="64"><path id="thumb-down-path" d="M1 21h4V9H1v12zM23 10.998c0-.799-.316-1.519-.879-2.062a2.982 2.982 0 0 0-2.221-.938h-6.31l.95-4.57.03-.33a1 1 0 0 0-.29-.7L13 2 6.59 8.41A2.006 2.006 0 0 0 6 9.83V19a2 2 0 0 0 2 2h9c.83 0 1.6-.4 2.09-1.09l3-4.294a3.014 3.014 0 0 0 .91-2.743z" /></svg></button><div></div></div></div></div>`;
if (container.parentNode) {
container.parentNode.insertBefore(aiOverviewDiv, container.nextSibling);
const syncOverviewWidth = () => {
if (!container.parentNode) {
return;
}
if (window.matchMedia('(max-width: 767px)').matches) {
aiOverviewDiv.style.width = '100%';
aiOverviewDiv.style.maxWidth = '100%';
aiOverviewDiv.style.minWidth = '0';
aiOverviewDiv.style.display = 'block';
aiOverviewDiv.style.flex = '0 0 100%';
aiOverviewDiv.style.alignSelf = 'stretch';
aiOverviewDiv.style.marginLeft = '0';
aiOverviewDiv.style.marginRight = '0';
return;
}
const containerRect = container.getBoundingClientRect();
const parentRect = container.parentNode.getBoundingClientRect();
const rawLeft = containerRect.left - parentRect.left;
const leftOffset = Math.max(0, rawLeft);
const maxAllowed = Math.max(0, parentRect.width - leftOffset);
const width = Math.min(containerRect.width, maxAllowed);
aiOverviewDiv.style.width = `${width}px`;
aiOverviewDiv.style.maxWidth = `${width}px`;
aiOverviewDiv.style.marginLeft = `${leftOffset}px`;
aiOverviewDiv.style.marginRight = '0';
};
syncOverviewWidth();
window.addEventListener('resize', syncOverviewWidth);
const thumbsUpBtn = document.getElementById('thumbs-up');
const thumbsDownBtn = document.getElementById('thumbs-down');
if (thumbsUpBtn) {
thumbsUpBtn.addEventListener('click', () => {
trackAnalyticsEvent("Search_ai_overview_thumbs_up");
document.getElementById('thumbs-up').classList.toggle('clicked');
postFeedback(true)
});
}
if (thumbsDownBtn) {
thumbsDownBtn.addEventListener('click', () => {
trackAnalyticsEvent("Search_ai_overview_thumbs_down");
document.getElementById('thumbs-down').classList.toggle('clicked');
postFeedback(false)
});
}
}
if (!document.getElementById('ai-overview-style')) {
const style = document.createElement('style');
style.id = 'ai-overview-style';
style.textContent = `
.ai-shimmer .shimmer-line {
height: 16px;
border-radius: 4px;
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 37%, #f0f0f0 63%);
background-size: 1000px 100%;
animation: shimmer 1.4s infinite;
margin-bottom: 30px;
}
.feedback_buttons{
margin-top: 11px;
float: right;
}
.link-list{
list-style: none;
padding: 0px;
margin: 0px;
}
.link-list li{
list-style: none;
margin: 0;
padding: 0;
}
.link-list li::marker {
content: "";
}
.link-list li a {
padding: 0px;
padding-top: 6px;
}
#thumbs-up, #thumbs-down {
background: none;
border: none;
cursor: pointer;
padding: 0;
}
#thumb-up-svg #thumb-up-path, #thumb-down-svg #thumb-down-path {
fill: #ffffff;
stroke: #000000;
stroke-width: 1;
transition: fill 0.5s ease-in, stroke 0.5s ease-in;
}
#thumbs-up.clicked #thumb-up-svg #thumb-up-path, #thumbs-down.clicked #thumb-down-svg #thumb-down-path {
fill: #00817D;
stroke: none;
}
#thumb-down-svg {
transform: scaleX(-1) rotate(180deg);
transform-origin: center;
}
#thumbs-up:disabled , #thumbs-down:disabled {
opacity: 0.5;
cursor: not-allowed;
pointer-events: none;
}
@keyframes shimmer {
0% { background-position: -1000px 0; }
100% { background-position: 1000px 0; }
}
@keyframes dotPulse {
0%, 20% { content: '.'; }
40% { content: '..'; }
60%, 100% { content: '...'; }
}
.ai-thinking-text::after {
content: '...';
animation: dotPulse 1.5s infinite;
}
.ai-thinking-icon {
flex-shrink: 0;
}
#ai-overview-block .ai_footer {
display: flex;
justify-content: space-between;
border-top: 1px solid #E6E6E6;
padding-top: 16px;
font-size: 16px;
color: #5F5753;
margin-top: 12px;
font-weight: 500;
}
#ai-overview-block .ai_footer p{
margin: 0px;
}
#ai-overview-block .ai_footer .feedback #thumbs-up {
margin: 0 24px 0 24px;
}
#ai-overview-block .link .linksource{
margin-left: 4px;
}
.toggle-text{
margin-right: 11px;
margin-left: 11px;
}
@media (max-width: 1024px) {
#ai-overview-block .ai_footer {
display: block;
}
#ai-overview-block .ai_footer .feedback{
display:grid;
}
#ai-overview-block .ai_footer .feedback_text{
margin-top: 15px;
margin-bottom: 10px;
}
#ai-overview-block .ai_footer .feedback #thumbs-up {
margin-left: 0px;
}
}
@media (max-width: 767px) {
#ai-overview-block .link{
display: grid;
}
#ai-overview-block .link .linksource{
margin-left: 0px;
}
#ai-overview-block {
width: 100% !important;
max-width: 100% !important;
min-width: 0 !important;
display: block !important;
flex: 0 0 100% !important;
align-self: stretch !important;
clear: both;
margin-left: 0 !important;
margin-right: 0 !important;
}
#ai-overview-block .ai-overview-content {
width: 100%;
min-width: 0;
overflow-wrap: anywhere;
word-break: normal;
}
#ai-overview-block .ai-overview-content > div {
padding: 24px 20px !important;
width: 100%;
box-sizing: border-box;
}
}
#ai-overview-block {
box-sizing: border-box;
max-width: 100%;
padding: 0 !important;
margin-top: 0;
margin-bottom: 0;
}
#ai-overview-block .ai-overview-content {
padding: 0 !important;
margin: 0 !important;
}
#ai-overview-block .ai-overview-content > div {
padding: 24px 20px !important;
margin-bottom: 0 !important;
}
#ai-overview-block .aisummary {
margin: 0;
display: block;
line-height: 1.5;
}
#ai-overview-block .aisummary.is-clamped {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 4;
overflow: hidden;
}
#ai-overview-block .summary-toggle {
display: none;
margin-top: 8px;
margin-bottom: 10px;
margin-left: 0;
color: #0662BB;
font-size: 16px;
font-weight: 500;
text-decoration: none;
cursor: pointer;
float: none !important;
vertical-align: baseline;
}
#ai-overview-block .summary-toggle:hover {
text-decoration: underline;
}
`;
document.head.appendChild(style);
}
const searchButton = document.querySelector('.search-result-button');
const inputField = document.getElementById('search-result');
function displayAIOverview(response) {
const shimmer = aiOverviewDiv.querySelector('.ai-shimmer');
const content = aiOverviewDiv.querySelector('.ai-overview-content');
if (response?.answer && response?.code) {
console.log(`UPS:: No answer for search: query: ${query}, TransactionId: ${transactionID}, response: ${JSON.stringify(response, null, 2)}`);
trackAnalyticsEvent("AI_Overview_no_answer");
}
if (response?.answer && !response?.code) {
console.log(`UPS:: AI response displayed. TransactionId: ${transactionID}`);
answer = response.answer;
url = response?.urls;
const summaryElement = aiOverviewDiv.querySelector('.aisummary');
const summaryToggle = aiOverviewDiv.querySelector('.summary-toggle');
const linkSourceText = aiOverviewDiv.querySelector('.linksource_text');
const list = aiOverviewDiv.querySelector('.link-list');
const toggleContainer = aiOverviewDiv.querySelector('.toggle-container');
summaryToggle.style.color = LINK_COLOR;
summaryToggle.style.float = 'none';
summaryToggle.style.marginTop = '8px';
summaryToggle.style.marginLeft = '0';
summaryToggle.style.display = 'none';
summaryToggle.innerText = 'See more';
summaryToggle.onclick = null;
if (linkSourceText) {
linkSourceText.style.clear = 'none';
linkSourceText.style.marginTop = '16px';
linkSourceText.style.display = 'none';
}
if (list) {
list.style.display = 'none';
}
if (toggleContainer) {
toggleContainer.style.display = 'none';
toggleContainer.style.marginTop = '8px';
}
if (toggleContainer && summaryToggle.parentElement !== toggleContainer) {
toggleContainer.insertAdjacentElement('afterend', summaryToggle);
}
const fullSummary = response.answer || '';
const MAX_SUMMARY_CHARS = 380;
const collapsedSummary = fullSummary.length > MAX_SUMMARY_CHARS
? `${fullSummary.slice(0, MAX_SUMMARY_CHARS).trimEnd()}...`
: fullSummary;
let isExpanded = false;
summaryElement.style.display = 'block';
const syncExpandedSections = (expanded) => {
const hasUrls = urls.length > 0;
if (linkSourceText) {
linkSourceText.style.display = expanded && hasUrls ? 'block' : 'none';
}
if (list) {
list.style.display = expanded && hasUrls ? 'block' : 'none';
}
if (toggleContainer) {
toggleContainer.style.display = expanded && hasUrls && urls.length > MAX_VISIBLE ? 'block' : 'none';
}
summaryToggle.style.marginTop = expanded && hasUrls ? '12px' : '8px';
};
const renderSummary = () => {
summaryElement.textContent = isExpanded ? fullSummary : collapsedSummary;
syncExpandedSections(isExpanded || fullSummary.length <= MAX_SUMMARY_CHARS);
};
const MAX_VISIBLE = 3;
const urls = response?.urls || [];
if (fullSummary.length > MAX_SUMMARY_CHARS) {
summaryToggle.style.display = 'block';
summaryToggle.innerText = 'See more';
summaryToggle.onclick = function (e) {
e.preventDefault();
isExpanded = !isExpanded;
summaryToggle.innerText = isExpanded ? 'See less' : 'See more';
renderSummary();
};
renderSummary();
} else {
summaryElement.textContent = fullSummary;
summaryToggle.style.display = 'none';
summaryToggle.onclick = null;
syncExpandedSections(true);
}
list.innerHTML = '';
toggleContainer.innerHTML = '';
urls.forEach(({ title, url }, index) => {
const li = document.createElement('li');
const a = document.createElement('a');
a.href = url;
a.target = "_blank";
a.textContent = title;
a.classList.add('track-link', 'no-utag');
a.style.color = LINK_COLOR;
a.addEventListener('click', function () {
console.log(`UPS:: User clicked source link: ${this.href} . TransactionId: ${transactionID}`);
trackAnalyticsEvent(this.href);
});
if (index >= MAX_VISIBLE) {
li.style.display = 'none';
li.classList.add('extra-item');
}
li.appendChild(a);
list.appendChild(li);
});
if (urls.length > MAX_VISIBLE) {
const toggleBtn = document.createElement('button');
toggleBtn.innerHTML = `<span class="toggle-text">See more</span><span class="toggle-icon"><svg xmlns="http://www.w3.org/2000/svg" width="10" height="6" viewBox="0 0 10 6" fill="none"><path d="M4.99082 5.8512C4.87748 5.8512 4.7688 5.82967 4.66478 5.78661C4.56061 5.74356 4.4688 5.68238 4.38936 5.60307L0.443109 1.65661C0.262415 1.47592 0.175539 1.26995 0.182484 1.0387C0.189428 0.807446 0.280887 0.603765 0.456859 0.427654C0.63297 0.251682 0.836651 0.163696 1.0679 0.163696C1.29915 0.163696 1.50283 0.251682 1.67894 0.427654L4.99498 3.76474L8.33186 0.427654C8.50797 0.251682 8.71165 0.167169 8.9429 0.174113C9.17415 0.181057 9.37783 0.272515 9.55394 0.448488C9.72991 0.624599 9.8179 0.82828 9.8179 1.05953C9.8179 1.29078 9.72755 1.4964 9.54686 1.6764L5.60061 5.60307C5.51561 5.68238 5.42103 5.74356 5.31686 5.78661C5.21283 5.82967 5.10415 5.8512 4.99082 5.8512Z" fill="#0662BB" /></svg></span>`;
toggleBtn.style.background = 'none';
toggleBtn.style.border = 'none';
toggleBtn.style.color = LINK_COLOR;
toggleBtn.style.cursor = 'pointer';
toggleBtn.style.padding = '8px 0';
toggleBtn.style.fontSize = '16px';
toggleBtn.style.display = 'flex';
toggleBtn.style.alignItems = 'center';
toggleBtn.style.gap = '6px';
let expanded = false;
toggleBtn.addEventListener('click', () => {
const extraItems = list.querySelectorAll('.extra-item');
expanded = !expanded;
extraItems.forEach(item => {
item.style.display = expanded ? 'list-item' : 'none';
});
toggleBtn.querySelector('.toggle-text').textContent = expanded ? 'See less' : 'See more';
const icon = toggleBtn.querySelector('.toggle-icon svg');
icon.style.transform = expanded ? 'rotate(180deg)' : 'rotate(0deg)';
});
toggleContainer.appendChild(toggleBtn);
}
shimmer.style.display = 'none';
content.style.visibility = 'visible';
content.style.opacity = '1';
content.style.display = 'block';
document.getElementById('thumbs-up').disabled = false;
document.getElementById('thumbs-down').disabled = false;
document.getElementById('thumbs-up').classList.remove('clicked');
document.getElementById('thumbs-down').classList.remove('clicked');
} else {
aiOverviewDiv.style.display = 'none';
}
}
async function initiateAPIRequest(inputValue) {
const aiOverviewDiv = document.getElementById('ai-overview-block');
const shimmer = aiOverviewDiv.querySelector('.ai-shimmer');
const content = aiOverviewDiv.querySelector('.ai-overview-content');
shimmer.style.display = 'block';
content.style.opacity = '0';
content.style.display = 'none';
aiOverviewDiv.style.display = 'block';
try {
const response = await getAIResponse(inputValue);
displayAIOverview(response);
if (response?.answer && !response?.code) {
setTimeout(() => {
trackAnalyticsEvent("AI_Overview_display");
}, 1000);
}
} catch (error) {
console.error('Error getting AI response:', error);
aiOverviewDiv.style.display = 'none';
}
}
if (searchButton && inputField) {
searchButton.addEventListener('click', async () => {
const inputValue = inputField.value.trim();
query = inputValue
if (!inputValue) return;
await initiateAPIRequest(inputValue);
});
const initialInput = inputField.value.trim();
query = initialInput;
if (initialInput) {
initiateAPIRequest(initialInput);
}
}
// }
clearInterval(checkInterval);
}, 300);
async function getAIResponse(query) {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 20000); // 20-seconds timeout
transactionID = uuidv4();
const data = {
"query": query,
"locale": `${window.utag_data.page_language}_${window.utag_data.page_country_code}`
};
if (dataSource !== undefined && dataSource !== null) {
data.data_source = dataSource;
}
try {
const envMetaTag = document.querySelector('meta[name="env"]');
const envValue = envMetaTag?.getAttribute('content');
let apiEndpoint;
if (envValue && envValue === '03')
apiEndpoint = "https://test-widgets.ups.com/api/enhanced-search/v1/recommendation"
else if (envValue && envValue === '02')
apiEndpoint = "https://stage-widgets.ups.com/api/enhanced-search/v1/recommendation"
else
apiEndpoint = "https://widgets.ups.com/api/enhanced-search/v1/recommendation"
const response = await fetch(apiEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'transId': transactionID,
'transactionSrc': 'search'
},
body: JSON.stringify(data),
signal: controller.signal
});
clearTimeout(timeoutId);
if (!response.ok) {
const responseBody = await response.json();
throw new Error(`status: ${response.status}, API response: ${JSON.stringify(responseBody, null, 2)}`);
}
const result = await response.json();
console.log('Success:', result.response);
return result.response;
} catch (error) {
clearTimeout(timeoutId);
console.error(`UPS:: AI response API failed with- ${error} . TransactionId: ${transactionID}`);
}
}
async function postFeedback(feedback) {
document.getElementById('thumbs-up').disabled = true;
document.getElementById('thumbs-down').disabled = true;
try {
const data = {
"query": query,
"answer": answer,
"urls": url,
"positiveExperience": feedback,
"locale": `${window.utag_data.page_language}_${window.utag_data.page_country_code}`,
"searchTransactionId": transactionID
};
const envMetaTag = document.querySelector('meta[name="env"]');
const envValue = envMetaTag?.getAttribute('content');
let apiEndpoint
if (envValue && envValue === '03')
apiEndpoint = 'https://test-widgets.ups.com/api/enhanced-search/v1/feedback'
else if (envValue && envValue === '02')
apiEndpoint = 'https://stage-widgets.ups.com/api/enhanced-search/v1/feedback'
else
apiEndpoint = 'https://widgets.ups.com/api/enhanced-search/v1/feedback'
const response = await fetch(apiEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'transId': uuidv4(),
'transactionSrc': 'search'
},
body: JSON.stringify(data)
});
if (!response.ok) {
const responseBody = await response.json();
throw new Error(`status: ${response.status}, API response: ${JSON.stringify(responseBody, null, 2)}`);
}
console.log(`UPS:: User submitted feedback as- ${feedback} . TransactionId: ${transactionID}`);
}
catch (error) {
console.error(`UPS:: Feedback API failed with : ${error} TransactionId: ${transactionID}`);
}
}
function trackAnalyticsEvent(linkName) {
const dataObject = {
data: {
link_page_name: "Search_AI_Overview",
link_name: linkName
},
callback: null,
uid_array: null,
actionType: "link",
};
if (typeof window.trackPageViewOrAction === 'function') {
window.trackPageViewOrAction(dataObject);
} else if (window.utag?.link) {
window.utag.link(dataObject);
}
}
function trackLinkClick(e) {
trackAnalyticsEvent(e?.href);
}
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
}
if (localStorage.getItem('watson_da') === 'true' && localStorage.getItem('enable_incomprehension') === 'true' && `${window.utag_data.page_language}_${window.utag_data.page_country_code}` === 'en_US') {
enableAIOverview(1);
}
</script>