-
-
Save LeaRomano-batch/e0c41c13664aad4c9d5ca9ff1890e5fb to your computer and use it in GitHub Desktop.
This file contains 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> (function () { | |
tp = window["tp"] || []; | |
/* Checkout related */ | |
/** | |
* Event properties | |
* | |
* chargeAmount - amount of purchase | |
* chargeCurrency | |
* uid | |
* expires | |
* rid | |
* startedAt | |
* termConversionId | |
* termId | |
* promotionId | |
* token_list | |
* cookie_domain | |
* user_token | |
* | |
*/ | |
function onCheckoutComplete(data) { | |
} | |
function onCheckoutExternalEvent() { | |
} | |
function onCheckoutClose(event) { | |
/* Default behavior is to refresh the page on successful checkout */ | |
if (event && event.state == "checkoutCompleted") { | |
location.reload(); | |
} | |
} | |
function onCheckoutCancel() { | |
} | |
function onCheckoutError() { | |
} | |
function onCheckoutSubmitPayment() { | |
} | |
/* Meter callback */ | |
function onMeterExpired() { | |
} | |
/* Meter callback */ | |
function onMeterActive() { | |
} | |
/* Callback executed when a user must login */ | |
function onLoginRequired() { | |
// this is a reference implementation only | |
// your own custom login/registration implementation would | |
// need to return the tinypass-compatible userRef inside the callback | |
// mysite.showLoginRegistration(function (tinypassUserRef) | |
// tp.push(["setUserRef", tinypassUserRef]); // tp.offer.startCheckout(params); // } | |
// this will prevent the tinypass error screen from displaying | |
return false; | |
} | |
/* Callback executed after a tinypassAccounts login */ | |
function onLoginSuccess() { | |
} | |
/* Callback executed after an experience executed successfully */ | |
function onExperienceExecute(event) { | |
} | |
/* Callback executed if experience execution has been failed */ | |
function onExperienceExecutionFailed(event) { | |
} | |
/* Callback executed if external checkout has been completed successfully */ | |
function onExternalCheckoutComplete(event) { | |
/* Default behavior is to refresh the page on successful checkout */ | |
location.reload(); | |
} | |
tp.push(["setAid", 'dZuxvvXZpe']); | |
tp.push(["setEndpoint", 'https://buy-eu.piano.io/api/v3']); | |
tp.push(['setPianoIdUrl', 'https://id-eu.piano.io']); | |
tp.push(["setUseTinypassAccounts", false ]); | |
tp.push(["setUsePianoIdUserProvider", true ]); | |
/* checkout related events */ | |
tp.push(["addHandler", "checkoutComplete", function(conversion){ | |
batchSDK(function (api) { | |
api.trackEvent("piano_onCheckoutComplete", { | |
attributes: { | |
"charge_amount" : conversion.chargeAmount, | |
"email": conversion.email, | |
"expiration_date": new Date(conversion.expires), | |
"user_token": conversion.user_token | |
} | |
}); | |
}); | |
}]); | |
tp.push(["addHandler", "checkoutClose", function(event) | |
{ | |
// The event object contains information about the state of closed modal | |
switch (event.state) | |
{ | |
case 'checkoutCompleted': | |
// User completed the purchase and now has access | |
// Usually it's a good practice to reload the page | |
batchSDK(function (api) { | |
api.trackEvent("piano_checkoutClose", | |
{ | |
attributes: { | |
"state" : "checkoutCompleted" | |
} | |
}); | |
}); | |
break; | |
case 'alreadyHasAccess': | |
// User already has access | |
// This state could be a result of user logging in during checkout process | |
// Usually it's a good practice to reload the page here as well | |
batchSDK(function (api) { | |
api.trackEvent("piano_checkoutClose", | |
{ | |
attributes: { | |
"state" : "alreadyHasAccess" | |
} | |
}); | |
}); | |
break; | |
case 'voucherRedemptionCompleted': | |
// User redeemed a gift voucher | |
// Normally gift redemption happens on a landing page, | |
// so logically it makes sense to redirect user to a home page after this | |
batchSDK(function (api) { | |
api.trackEvent("piano_checkoutClose", | |
{ | |
attributes: { | |
"state" : "voucherRedemptionCompleted" | |
} | |
}); | |
}); | |
break; | |
case 'close': | |
// User did not complete the purchase and simply closed the modal | |
batchSDK(function (api) { | |
api.trackEvent("piano_checkoutClose", | |
{ | |
attributes: { | |
"state" : "close" | |
} | |
}); | |
}); | |
} | |
}]); | |
tp.push(["addHandler", "checkoutCustomEvent", onCheckoutExternalEvent]); | |
tp.push(["addHandler", "checkoutCancel", onCheckoutCancel]); | |
tp.push(["addHandler", "checkoutError", onCheckoutError]); | |
tp.push(["addHandler", "checkoutSubmitPayment", onCheckoutSubmitPayment]); | |
/* user login events */ | |
tp.push(["addHandler", "loginRequired", function(params){ | |
batchSDK(function (api) { | |
api.trackEvent("piano_onLoginRequired"); | |
}); | |
}]); | |
tp.push(["addHandler", "loginSuccess", function(data){ | |
batchSDK(function (api) { | |
api.trackEvent("piano_onLoginSuccess", { | |
attributes: { | |
"registration": data.registration, | |
"source": data.source | |
} | |
}); | |
}); | |
}]); | |
/* registration */ | |
tp.push(["addHandler", "registrationSuccess", function (data) { | |
batchSDK(function (api) { | |
api.trackEvent("piano_onRegistrationSuccess", { | |
attributes: { | |
"user_id": data.user.sub, | |
"email": data.user.email, | |
"given_name": data.user.given_name | |
} | |
}); | |
}); | |
}]); | |
/* meter related */ | |
tp.push(["addHandler", "meterExpired", onMeterExpired]); | |
tp.push(["addHandler", "meterActive", onMeterActive]); | |
tp.push(["addHandler", "experienceExecute", onExperienceExecute]); | |
tp.push(["addHandler", "experienceExecutionFailed", onExperienceExecutionFailed]); | |
/* external checkout related events */ | |
tp.push(["addHandler", "externalCheckoutComplete", onExternalCheckoutComplete]); | |
tp.push(["init", function () { | |
tp.experience.init() | |
}]); | |
})(); | |
</script> | |
<script> | |
// do not change this section | |
// |BEGIN INCLUDE TINYPASS JS| | |
(function(src){var a=document.createElement("script");a.type="text/javascript";a.async=true;a.src=src;var b=document.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b)})("https://cdn-eu.piano.io/api/tinypass.min.js"); | |
// |END INCLUDE TINYPASS JS| | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment