Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync Sprint 22 deploy to Stage #249

Merged
merged 21 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
aaec9fa
24PW: New Template - Paid Blog (#219)
hero-dokane Oct 3, 2024
b65b41b
24PW: Pawpack Page - EDS Build (#215)
hero-dokane Oct 3, 2024
68d13c8
Merge remote-tracking branch 'origin/stage' into develop
BaDos Oct 3, 2024
643de65
Added Shipping of Tag to the summary page (#221)
BaDos Oct 4, 2024
e00a58f
24PW: Pawpack Page - EDS Build - QA Feedback (#222)
hero-dokane Oct 7, 2024
07d5622
Merge branch stage into develop
hero-dokane Oct 7, 2024
31f4da7
WIP on bugfix/mobile-nav-redirect-visibility (#224)
hero-dokane Oct 7, 2024
2392032
24PW: Pet Insurance - Aggregator Widget (#225)
pgilmore-phi Oct 8, 2024
ba35c4d
Revert decorateButtons function, apply callout cta styling (#226)
hero-dokane Oct 8, 2024
66e50df
Adding thank you page dataLayer object (#230)
pgilmore-phi Oct 11, 2024
47026d2
Back sync develop with main (#234)
pgilmore-phi Oct 15, 2024
d2a50c3
Merge feature pm 568 abandon cart changes into develop for testing (#…
pgilmore-phi Oct 15, 2024
95e36b9
Feature pm 568 abandon cart: update species ID ternary condition (#237)
pgilmore-phi Oct 15, 2024
eafd2e3
Salesforce Abandoned Cart: refactored payload (#239)
pgilmore-phi Oct 16, 2024
4bceb66
Salesforce Abandoned Cart: Add upsert on thank you page (#241)
pgilmore-phi Oct 17, 2024
00210f0
Added condition to load paid blog header fragment based on paid blog …
pgilmore-phi Oct 17, 2024
08b8290
wrap tracking data inside ecommerce object (#242)
pgilmore-phi Oct 17, 2024
0117118
dataLayer updates: add currency to purchase event (#243)
pgilmore-phi Oct 18, 2024
896fc64
Sync to sprint deploy: Salesforce Abandoned Cart (#248)
pgilmore-phi Oct 21, 2024
6d53e67
Added condition to load paid blog header fragment based on paid blog …
pgilmore-phi Oct 21, 2024
2bb1678
Merge branch 'stage' into release/sprint-22-deploy
pgilmore-phi Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions blocks/header-paid/header-paid.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ function instrumentTrackingEvents(header) {
}

export default async function decorate(block) {
// default paid header
let baseHeaderUrl = '/fragments/us/header-paid';
if (isCanada) {
baseHeaderUrl = '/fragments/ca/header-paid';
}
// paid blog page header
if (document.body.className.includes('paid-blog-page')) {
baseHeaderUrl = '/fragments/us/header-paid-blog';
if (isCanada) {
baseHeaderUrl = '/fragments/ca/header-paid-blog';
}
}

const headerPaidContent = await loadFragment(baseHeaderUrl);

Expand Down
2 changes: 2 additions & 0 deletions blocks/plans-quote/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Loader from './loader.js';
import APIClient from '../../scripts/24petwatch-api.js';
import {
COOKIE_NAME_SAVED_OWNER_ID,
SS_KEY_FORM_ENTRY_URL,
EMAIL_REGEX,
MICROCHIP_REGEX,
PET_PLANS_LPM_URL,
Expand Down Expand Up @@ -691,6 +692,7 @@ export default function formDecoration(block, apiBaseUrl) {

// remember the critical information for future steps
setCookie(COOKIE_NAME_SAVED_OWNER_ID, formData.ownerId);
sessionStorage.setItem(SS_KEY_FORM_ENTRY_URL, window.location.href);
window.location.href = `.${PET_PLANS_SUMMARY_QUOTE_URL}`; // ex: './summary-quote'
}

Expand Down
64 changes: 64 additions & 0 deletions blocks/plans-quote/summary-quote.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ import Loader from './loader.js';
import formDecoration from './form.js';
import {
COOKIE_NAME_SAVED_OWNER_ID,
SS_KEY_FORM_ENTRY_URL,
getCookie,
getSelectedProductAdditionalInfo,
getItemInfoFragment,
} from '../../scripts/24petwatch-utils.js';
import { getConfigValue } from '../../scripts/configs.js';

export default async function decorateSummaryQuote(block, apiBaseUrl) {
// initialize form based on results from the previous step
const APIClientObj = new APIClient(apiBaseUrl);
Loader.addLoader();

const salesforceProxyEndpoint = await getConfigValue('salesforce-proxy');
const ownerId = getCookie(COOKIE_NAME_SAVED_OWNER_ID);
const entryURL = sessionStorage.getItem(SS_KEY_FORM_ENTRY_URL);

let ownerData = [];
let petsList = [];
Expand Down Expand Up @@ -73,8 +77,68 @@ export default async function decorateSummaryQuote(block, apiBaseUrl) {
console.log('Failed to get the purchase summary for owner:', ownerData.id, ' status:', status);
}
}

Loader.hideLoader();

async function sendDataToSalesforce(owner, products, pets) {
Loader.showLoader();
if (!owner || !owner.email || !owner.id) {
// eslint-disable-next-line no-console
console.error('invalid owner data');
}

if (!products || !products[0] || !products[0].petID) {
// eslint-disable-next-line no-console
console.error('Invalid selected products data');
}

if (!pets || !pets[0] || !pets[0].petName || !pets[0].speciesId === undefined) {
// eslint-disable-next-line no-console
console.error('Invalid pets list data');
}

if (!entryURL) {
// eslint-disable-next-line no-console
console.error('Invalid entry URL');
}

const payload = {
payload: {
Data: {
ContactKey: ownerData.email,
EmailAddress: ownerData.email,
OrderCompleted: false,
OwnerId: ownerData.id,
PetId: selectedProducts[0].petID,
PetName: petsList[0].petName,
SiteURL: entryURL,
Species: petsList[0].speciesId === 1 ? 'Dog' : 'Cat',
},
EventDefinitionKey: 'APIEvent-6723a35b-b066-640c-1d7b-222f98caa9e1',
ContactKey: ownerData.email,
},
};

const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
};
await fetch(salesforceProxyEndpoint, options);

Loader.hideLoader();
}

// Send data for abandoned cart journey
try {
await sendDataToSalesforce(ownerData, selectedProducts, petsList);
} catch (error) {
// eslint-disable-next-line no-console
console.error('There was an error sending the data to Salesforce', error);
}

function getSelectedProduct(petId) {
return selectedProducts.find((item) => item.petID === petId);
}
Expand Down
36 changes: 36 additions & 0 deletions blocks/thank-you/thank-you.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ import APIClient, { getAPIBaseUrl } from '../../scripts/24petwatch-api.js';
import {
COOKIE_NAME_SAVED_OWNER_ID,
deleteCookie,
SS_KEY_FORM_ENTRY_URL,
CURRENCY_CANADA,
CURRENCY_US,
} from '../../scripts/24petwatch-utils.js';
import { isCanada } from '../../scripts/lib-franklin.js';
import { trackGTMEvent } from '../../scripts/lib-analytics.js';
import { getConfigValue } from '../../scripts/configs.js';

// prep for API calls
const apiBaseUrl = await getAPIBaseUrl();

const APIClientObj = new APIClient(apiBaseUrl);

// salesforce proxy
const salesforceProxyEndpoint = await getConfigValue('salesforce-proxy');

// Sequence of steps to get the owner info from the API

// Step 1 - get the paymentPortalCustomerId from the UUID (aka paymentProcessorId)
Expand Down Expand Up @@ -89,6 +94,8 @@ async function getTransaction(paymentProcessorId) {
export default async function decorate() {
// delete cookie with customer id
deleteCookie(COOKIE_NAME_SAVED_OWNER_ID);
// unset sessionStorage form entry URL
sessionStorage.removeItem(SS_KEY_FORM_ENTRY_URL);

const urlParams = new URLSearchParams(window.location.search);
const paymentProcessorId = urlParams.get('PaymentProcessorCustomerId');
Expand Down Expand Up @@ -180,6 +187,35 @@ export default async function decorate() {
// send the GTM event
trackGTMEvent('purchase', trackingData);

// Salesforce Upsert
async function setUpsertToSalesforce(email) {
const payload = {
payload: {
Data: {
OrderCompleted: true,
},
ContactKey: email,
},
};

const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
};
await fetch(salesforceProxyEndpoint, options);
}

// Send data for abandoned cart journey
try {
await setUpsertToSalesforce(getOwnerDetails.email);
} catch (error) {
// eslint-disable-next-line no-console
console.error('There was an error sending the data to Salesforce', error);
}

const printButton = document.createElement('button');
printButton.classList.add('button');
printButton.innerHTML = 'Print <span class="visually-hidden">this page</span>';
Expand Down
3 changes: 3 additions & 0 deletions scripts/24petwatch-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export function getQueryParam(param, defaultValue = null) {
return urlParams.has(param) ? urlParams.get(param) : defaultValue;
}

// ----- sessionStorage / localStorage helpers -----
export const SS_KEY_FORM_ENTRY_URL = 'formEntryURL';

// ----- cookie helpers -----
export const COOKIE_NAME_FOR_PET_TAGS = 'ph.PetTagQuote';
export const COOKIE_NAME_FOR_PET_PLANS = 'ph.PetPlanQuote';
Expand Down
Loading