Javascript - when a tracking call has completed?

Avatar

Avatar

pwolly-cr

Avatar

pwolly-cr

pwolly-cr

22-09-2020

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!
View Entire Topic

Avatar

Avatar

evolytics_brian

MVP

Avatar

evolytics_brian

MVP

evolytics_brian
MVP

22-09-2020

tbaker73
Thanks @evolytics_brian. 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?
evolytics_brian
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.
yuhuisg
@tbaker73 out of curiosity, why do you need to call a s.tl() immediately after a s.t() ?
tbaker73
@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). @evolytics_brian 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?
evolytics_brian
@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