The external-event directive is supported in My Account templates. Add it to an element, and Piano sends a custom event to your website when a subscriber clicks that element. For example, you can run your own code when a subscriber selects a button in My Account.
-
Add the
external-eventdirective to an element in your My Account template, and set an event name:HTML<span external-event="cancel-sub-click">Cancel subscription</span> -
On the page of your website that embeds My Account, add a handler for the
customEventcallback:JavaScripttp.push(['addHandler', 'customEvent', function(event) { if (event.eventName === 'cancel-sub-click') { // Your code here } }]);
The event includes the eventName you set and its params. For all callbacks, see Piano JavaScript Callbacks.
You can also push custom events from the My Account iframe to your website's front-end application with post messages.
For example, if you'd like to listen to a click on the "Add Credit Card" button, you can add the following code to the My Account Wallet Components template:
<t onclick="parent.postMessage('Add Credit Card Event', '<your_website_url>/myaccount.html');">Add Credit Card</t>
And replace the <your_website_url> with the URL of your website where you'd like to receive the post messages.