Load Rule Based on Ajax Data

powem
Visitor
powem

Hello,

I need to base a load rule on a value returned by an Ajax call. This call is executed in an extension. It returns the value of a response header. This value is pushed into utag_data. That part works, after the page load I can see the value in the data layer. However, a load rule based on this value in the DL doesn't see it.  Even though, as I understand it, the rule should be run twice. I thought that if it ran again at the end of the page load, it would see the value. Nope.

I've gone over the order of operations, and tried moving the scope of the extension: Pre-loader, All Tags, the tag itself. I moved the extension to the top of the list, with the thought that this might give it some milliseconds more time to complete. No joy. I tried setting the Ajax call to sync, but this is a bust. It does not, near as I can make out, affect the page load at all. It merely makes the send() function wait until the response is complete before returning it. Which is probably worse, from a timing aspect.

A snippet that reproduces the request:

xhr.onreadystatechange = function () {
    if (xhr.readyState === 2) {
        ans = xhr.getResponseHeader(hdr);
        if (ans !== '' && ans !== null && ans !== "undefined") {
            window.ans = ans;
            that._datalayer[that._dataname] = ans;
        }
    }
};

As I indicated, the returned value does land where I expect it to be. The $64,000,000 question: how can I use this value in a load rule?

Thanks. 

"If it sounds good, it is good." - Duke Ellington
3 REPLIES 3

Load Rule Based on Ajax Data

Tealium Employee

Hi @powem

Are you doing a utag.link or utag.view function call on the content update?  the utag.link / utag.view will re-evaluate the load rules based on the current data layer (including your Ajax data) 

Try having a look at this post about tracking, which describes tracking on a single page application: https://community.tealiumiq.com/t5/JavaScript-utag-js/Page-Tracking/ta-p/15563#toc-hId--445688209

Many thanks

Steve Lake

 

 

Load Rule Based on Ajax Data

powem
Visitor
powem

Hello,

Thanks for the reply. This task currently considers only load rules based on the returned value. I have seen some discussion about using .view() but I'm not sure how I could replace, e.g., a GA pageview tag firing with a utag.view(). Is there any documentation on such an approach? I'm game to try it. I think the LR approach would work for links, since the proper value would be already in the data layer at that point. 

Thanks.

mp

"If it sounds good, it is good." - Duke Ellington

Load Rule Based on Ajax Data

powem
Visitor
powem

Hello,

Okay, you have put me onto a course that seems correct. Many thanks for that.

I tested firing two tags from within the utag.view(), and after accounting for operator error, it seems to be the correct answer to my issue. Or, at least, a significant portion of it.

Can't thank you enough.

mp

 

"If it sounds good, it is good." - Duke Ellington