Or Google Tag Manager, whichever is handier.
Here’s a short snippet of code I used to use to notify my team of recent conversions, as they took place. The delay was less than 3 seconds.
<script>
let url = 'https://hooks.slack.com/services/XXXXXXXXX/YYYYYYYYY/ZZZZZZZZZZZZZZZZZZZZZZ';
let text = 'New event - {{customEventId}} - completed!';
$.ajax({
data: 'payload=' + JSON.stringify({
"text": text,
}),
dataType: 'json',
processData: false,
type: 'POST',
url: url
});
</script>
Notes & Details
- Get the hook URL from Slack.
- I initially used jQuery for this, but it can be easily switched to use XHR or Fetch API. It’s pretty old, though, and I won’t do it. I’m not using Slack anymore.
{{customEventId}}
is a Google Tag Manager variable.