Sorry for the confusion, you're right that my initial suggestion doesn't work. The problem is that the callback to the Generic Tag doesn't include the response as an argument.
I've just set up a successful test:
Use a Custom Container tag to make your API request using xhr (allows you to use the response in your utag.link call). We could use a JS extension instead, but IMO it's much cleaner to use Tags for all outgoing requests for the sake of possible Consent Management, etc. Just put this code (modify the requested resource and the utag.link as needed) between the 'Start Tag Sending Code' and 'End Tag Sending Code' comments:
/* Start Tag Sending Code */ // could add mapping to make this more generalized, hardcoding for now as POC var xhr = new XMLHttpRequest(); var apiResource = 'https://putsreq.com/JTBXYfs30pQvioNwgV2Y' xhr.open('GET', apiResource); xhr.onload = function() { if (xhr.status === 200) { var data = {}; data.event_name = "data_callback"; data.foo = xhr.responseText; utag.link(data); } else { utag.DB('XHR API Request failed. Returned status of ' + xhr.status); } }; xhr.send(); /* End Tag Sending Code */
No other changes are needed to that template.
Assign a Load Rule to that Custom Container so it only fires when the session cookie isn't yet defined
Set up a Persist Data Value Extension to persist 'foo' from your 'data_callback' event
Sorry for all the back-and-forth on this one, let me know if that works for you.
Best Caleb
... View more