Last active
March 26, 2024 16:01
-
-
Save adardesign/0ab74f941d5f6a09e4ae00cd2b919427 to your computer and use it in GitHub Desktop.
paypal-insight-sdk-extended
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
try{ | |
var eventName = {{Event}} | |
if(eventName === "checkout-event"){ | |
var data = {{dlv - data}}; | |
if(data.includes("payment method selected")){ | |
eventName = 'select_payment_method'; | |
} | |
if(data.includes("contact info submitted")){ | |
eventName = "submit_checkout_email"; | |
} | |
} | |
var isLoggedIn = {{cookie - loggedin}} === "True"; | |
var sessionId = {{cookie - SID3}} | |
var ecommerce = {{dlv - ecommerce}}; | |
var watts = window.ssWATTS.ssCounted || ""; | |
var isInCampaign = watts.includes('pp_checkout') | |
var experiment = [{ | |
exp_name: "axo-experiment", | |
treatment_name: isInCampaign ? (watts.includes('pp_checkout:Variation') ? "test" : "control") : "not-in-campaign", | |
ramp: "15%" | |
}] | |
var eventObject = { | |
page_type: "checkout", | |
session_id: sessionId, | |
experiment: experiment | |
} | |
if(eventName === "select_payment_method"){ | |
var payment_method = data.split(":")[1]; | |
payment_method = payment_method.trim(); | |
var payment_methodValue = payment_method; | |
if(payment_method === "creditCard") payment_methodValue = "card" | |
if(payment_method === "payPal") payment_methodValue = "paypal" | |
if(payment_method === "bml") payment_methodValue = "paypal_credit" | |
if(payment_method === "googlepay") payment_methodValue = "google_pay" | |
eventObject.payment_method_selected = payment_methodValue | |
} | |
if(eventName === "begin_checkout" || eventName === "end_checkout"){ | |
eventObject.amount = { currency_code: "USD", value: String(ecommerce.value) }; | |
eventObject.user_data = { country: "US", is_store_member: isLoggedIn }; | |
} | |
paypalInsight && paypalInsight("event", eventName, eventObject) | |
}catch(error){ | |
console.error("paypalInsight error",error) | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment