Highlighted

Capture AJAX call results within block before Utag.js runs

Bronze Contributor
Bronze Contributor
There is one AJAX call returns the user profile object in before loading the Utag. Since the returning time is uncertain of that Ajax call, could be before or after the Utag.js loads up, so calling utag.link cannot give persistent results.
3 REPLIES 3
Highlighted

Capture AJAX call results within block before Utag.js runs

Employee Emeritus
Hey Marchi, What if you place the utag.link function within a JavaScript extension scoped to DOM Ready? This will check for the value returned in the AJAX response later in the page load and may have enough of a wait to pick up the value more consistently. If that is still inconsistent, we could help you set up a custom listener for the AJAX response that will wait until the response is complete before triggering the utag.link function. You can reach out to your Account Manager to start getting this set up. Cheers
Highlighted

Capture AJAX call results within block before Utag.js runs

Employee Emeritus
I think the best way to do this would be to fire off the utag.link() or utag.view() call in the success callback of the ajax request. That way youre not worrying about timing, you simply make the utag call after the request has finished processing. like: $.ajax({ url : "AJAX_POST_URL", type: "POST", data : formData, success: function(data) { utag.data.ajaxResponse = data; utag.view(utag.data); } });
Highlighted

Capture AJAX call results within block before Utag.js runs

Employee Emeritus
This would definitely be the preferred method if you can alter the ajax request. +1