Skip to content

Commit

Permalink
refactor: Remove uniqueness from events in Checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
julianajlk committed Nov 1, 2024
1 parent d63254d commit 37aabc9
Showing 1 changed file with 20 additions and 34 deletions.
54 changes: 20 additions & 34 deletions src/payment/checkout/Checkout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ class Checkout extends React.Component {
constructor(props) {
super(props);
this.paypalButtonRef = React.createRef();
this.paypalButtonClicked = false;
this.placeOrderButtonClicked = false;
this.observer = null;
this.hasBeenShown = {};
this.state = {
hasRedirectedToPaypal: false,
};
Expand Down Expand Up @@ -92,21 +89,16 @@ class Checkout extends React.Component {

handleIntersectionObserver = (entry) => {
const elementId = entry.target?.id;

// Single call behavior
if (!this.hasBeenShown[elementId]) {
const tagularElement = {
title: PaymentTitle,
url: window.location.href,
pageType: 'checkout',
elementType: ElementType.Button,
position: elementId,
name: ElementType.Button,
...(elementId === 'PayPalButton' ? { text: 'PayPal' } : {}),
};
this.props.trackElementIntersection(tagularElement);
this.hasBeenShown[elementId] = true;
}
const tagularElement = {
title: PaymentTitle,
url: window.location.href,
pageType: 'checkout',
elementType: ElementType.Button,
position: elementId,
name: ElementType.Button,
...(elementId === 'PayPalButton' ? { text: 'PayPal' } : {}),
};
this.props.trackElementIntersection(tagularElement);
};

handleRedirectToPaypal = () => {
Expand Down Expand Up @@ -136,19 +128,16 @@ class Checkout extends React.Component {
);

// Red Ventures Cohesion Tagular Event Tracking for PayPal
if (!this.paypalButtonClicked) {
this.paypalButtonClicked = true;
const tagularElement = {
title: PaymentTitle,
url: window.location.href,
pageType: 'checkout',
elementType: ElementType.Button,
text: paymentMethod,
name: paymentMethod.toLowerCase(),
};

this.props.trackPaymentButtonClick(tagularElement);
}
const tagularElement = {
title: PaymentTitle,
url: window.location.href,
pageType: 'checkout',
elementType: ElementType.Button,
text: paymentMethod,
name: paymentMethod.toLowerCase(),
};

this.props.trackPaymentButtonClick(tagularElement);

this.props.submitPayment({ method: paymentMethod.toLowerCase() });
};
Expand Down Expand Up @@ -206,9 +195,6 @@ class Checkout extends React.Component {
productList: this.getProductList(),
};

if (!this.placeOrderButtonClicked) {
this.placeOrderButtonClicked = true;
}
this.props.submitPayment({ method: 'stripe', tagularElement, ...formData });
};

Expand Down

0 comments on commit 37aabc9

Please sign in to comment.