Record Which User Clicked Action Button - Zapier Integration
R
Rutger Hofste
I'm working on a collaborative Stacker app. Not knowing which user clicked the action button is a major limitation.
D
David Gruhin
I wrote a script to do this, and Stacker support was willing to implement it for me. Instead of a Stacker button triggering a zap I have the button simply updating a record in a table with a default value and show nothing to the end user. I then hijack the button with some JS
document.body.addEventListener('click', function(event) {
// Check if the clicked element has the specific class
if (event.target.classList.contains('THE CLASS OF YOUR BUTTON')) {
handleClick(event.target);
}
});
const handleClick = function(buttonElement) {
// Retrieve the user object from localStorage
const userString = localStorage.getItem('user');
const user = JSON.parse(userString);
// Extract the email address
const userEmail = user.email;
// Get the current URL, For my purposes I also wanted the URL so I could easily get the RECORD ID to use in my zap to looking the corresponding record in airtable for the thing my user was viewing.
const currentUrl = window.location.href;
// ZAPIER Webhook URL - Customize the url as needed
const webhookUrl = 'https://hooks.zapier.com/hooks/catch/YOUR-WEBHOOK-HERE';
// Payload to be sent - including the email and current URL
const data = {
email: userEmail, //Include logged in user email
url: currentUrl // Include current URL
};
// Send the webhook using fetch API
fetch(webhookUrl, {
method: 'POST',
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
// Handle success - maybe show a confirmation message
})
.catch((error) => {
console.error('Error:', error);
// Handle error - show an error message
});
After all of that worked I refactored my code to do a myriad of other things. Obviously this is not the most ideal thing in the world but it does work.
N
Noam Say
This simple feature would open a large range of possibilities in terms of automated workflows that can be created.