If you need to send a service like Zapier, you can simply add a βcustom codeβ action to your buttons when you are capturing data in Amped.
β
Go to Button Actions -> Custom Code
β
This will run in the order it is in the Button Actions list
Built in "input" variable available from Custom Code
From a Custom Code block on Button Actions, you can use the already established variable 'input' which is an array for inputs that have been captured up to this point.
e.g. input.email or input.phone_number or any inputs you have set by their name.
β
You can also access extra information about the current Campaign through the predefined variable of "metadata"
βmetadata containsβ
metadata.campaign_id
βmetadata.campaign_title
βmetadata.variation_id
βmetadata.variation_name
β
Copy and Paste-able Code for Custom Code Action
var webhook_url = "WEBHOOK_URL_HERE"; //π replace with Zapier webhook URL
// π //////////////////////////////////////////
// You don't need to edit anything below this line.
////////////////////////////////////////////////
// payload is what will be sent to the webhook. We can fill it in with data that needs to be sent to the webhook.
var payload = {};
// 'input' contains any inputs captured. eg: the email input can be accessed through input.email or input.phone_number
payload = input;
// If we also have user properties and we want to include them in the payload, we can access them from
var userProperties = JSON.parse(window.localStorage.getItem(`amped-${ampedConfig.accountId}-userProperties`));
if (userProperties){
payload.userProperties = userProperties;
}
payload.sms_optin_date = new Date().toISOString();
// //////////////////////////////////////////
// Keep this and don't edit - This is sending request to webhook and continuing with Amped actions.
////////////////////////////////////////////////
fetch(webhook_url, {
method: 'POST',
mode: "no-cors",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(payload),
})
.then(response => {
if (response.ok) {
return response.json();
} else {
console.log('Amped.io: Custom Webhook Error: Network issue');
}
})
.then(data => {
console.log('Amped.io: Custom Webhook sent:', data);
})
.catch((error) => {
console.log('Amped.io: Custom Webhook error:', error);
});
resolve(); //tells your actions to continue. Othwerwise the campaign will load indefinitely, break, and it will timeout.
β