I'm using google tag manager in my website, I would like to send a http request to a 3rd party service incase someone visits a specific page.
the trigger is setup well, what i'm trying to figure is if the url for post is for example:
"https://hook.eu1.make.com/g88t9og168tfh4uejyh55j5hbao7nutw" how do I wrap it in custom code so it will fire everytime the page is loaded? any javascript examples ?
Thanks
This is possible. Add a custom html tag in Tag Manager which fires on the pages you want. Add and change this code into the html tag:
<script>
var headers = new Headers();
headers.append("Content-Type", "application/json");
var body = {
"yourdata": yourdata,
"user_agent": navigator.userAgent,
"url": window.location.origin + window.location.pathname
};
var options = {
method: "POST",
headers: headers,
mode: "cors",
body: JSON.stringify(body)
};
fetch("https://hook.eu1.make.com/YOUR_WEBHOOK", options);
</script>