-
Notifications
You must be signed in to change notification settings - Fork 0
/
dr-gtm.html
29 lines (25 loc) · 950 Bytes
/
dr-gtm.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<script>
var url = "https://api.decisionrules.io/rule/solve/your-rule-id"; // Enter your rule ID here
var solverKey = "your-solver-api-key"; // Enter your Solver API Key here
var data = {"data":{"Input attribute":"Call to DecisionRules"}}; // Enter your input data here
var drResponse = null;
fetch(url, {
method: "POST",
headers: {"Content-Type": "application/json",
"Authorization": "Bearer " + solverKey},
body: JSON.stringify(data)
}).then(function (res) {
return res.json();
}).then(function (data) {
// Use the response here
console.log("Response from DecisionRules was", data);
drResponse = data;
// Trigger a custom event "dr-response" in GTM & save data to variable "dr-response-data"
dataLayer.push({
'event': 'dr-response',
'dr-response-data': drResponse[0]["Output Attribute"]
});
}).catch(function (e) {
console.log("DR Error", e);
});
</script>