Expand my Community achievements bar.

SOLVED

Javascript - when a tracking call has completed?

Avatar

Level 2
Hello!
Does anyone know if there is a reliable way in javascript to detect whether the adobe analytics page tracking call (s.t()) has completed?  Currently, we are attempting to test for this via the below javascript (that tries to determine the state of the image beacon added to the page):
 
var pageViewComplete = function(){
    var pageViewPixel = window.s_i_scglobal;
    if (pageViewPixel && pageViewPixel.src && (pageViewPixel.src.indexOf('/b/ss/') >= 0) && pageViewPixel.complete){
      return true;
    }
    return false;
  };
 
We have noted that on occasion, the page view is recorded via an AJAX post to our adobe server vs the inclusion of the <img> tag, so the above code doesn't not always work.
 
Is there any Adobe supported way to test for this?
 
Thanks!
1 Accepted Solution

Avatar

Correct answer by
Level 8
6 Replies

Avatar

Correct answer by
Level 8

Avatar

Level 1
Thanks @Brian_Johnson_. We had looked into using registerPostTrackCallback but in this case, the handler needs to make a link tracker call back to our Adobe (using s.tl()). The docs for registerPostTrackCallback warn against this - "Do not call any tracking calls like t() or tl() inside the registerPostTrackCallback variable. Tracking functions in this variable cause an infinite loop of image requests!" Any other thoughts?

Avatar

Level 8
Assuming you just need to fire the extra s.tl() call once after the initial page load call, you could just set a true/false flag to false before initiating the page call. Next, either with a Promise, or setInterval(), watch for the flag to become true and fire the s.tl() call when it does. (Take care that it only executes this part once, or you could wind up with an abundance of s.tl() calls.) In registerPostTrackCallback, flip the flag to true, which should ensure that the page load call fires first, followed by the s.tl() call.

Avatar

Community Advisor
@tbaker73 out of curiosity, why do you need to call a s.tl() immediately after a s.t() ?

Avatar

Level 1
@yuhuisg The problem we are trying to solve is that the page calls on our site depend on an ajax call to complete before firing. The new platform we are integrating with requires a link tracker call to record its additional metrics, and this happens asynchronously (we can't control the timing of it - the trigger to it is nested in a callback from a script they load async). At certain times, the s.tl() call for the vendor metrics recording can precede the page tracking call (which corrupts the data in our direct traffic report). @Brian_Johnson_ In the idea you proposed, wouldn't registerPostTrackCallback also fire after the call to s.tl() in which case if that happens to go first, we'd still have this problem?

Avatar

Level 8
@tbaker73 - My suggestion was to only trigger the s.tl() when you knew the s.t() had already fired. One way to accomplish that would be with a simple flag and an interval as in this simple example: https://gist.github.com/hitGovernor/dc3e7120830a9feaea16c6840715d36c