Expand my Community achievements bar.

SOLVED

Run code after _satellite.pagebottom or _satellite.track are completed in callback or Promise

Avatar

Level 1

Hello,

I was wondering if it is possible to run any code after the async functions _satellite.pagebottom or _satellite.track are complete. We need to navigate user to another page and as I saw running a rule with _satellite.track is making async http requests. Obviously if I just add window.replace after _satellite.track it will cancel those requests and rule would not be executed. What we need is either some kind of callback in _satellite.track function or for it to return a Promise (currently it returns undefined). Right now I am relying on setTimeout and hoping that _satellite.track will finish within the number of seconds set in setTimeout but that is very ugly and hack solution. We need callback or Promise that will assure us that _satellite.track is complete.

Please advise. Thank you.

Best regards,

Goran Blazin

Sprinting Software

1 Accepted Solution

Avatar

Correct answer by
Level 3

We ran into something similar with click tracking mboxes in target.

our solution was to override the onclick and href values of the element clicked, then in the success AND error states of the click tracking call, we then created a new dom a tag on the fly, added the href back for the next piece of js to use the window.location change.

works well, kinda hacky, but that's what we had to do in order to deal with the window.location changes

better way is to not do the window.replace and instead rely on native browser element functionality for changing the location. depends on your setup. we aren't on a SPA site with angular, but we have a lot of ajaxy reqs.

``` code

var clickTrack = function(click){

                          adobe.target.trackEvent({

                            'mbox':'mboxClickTrack',

                            'preventDefault': true,

                            'params': {

                                'menuClick': click

                            },

                            'success': function(){

                                jQuery(this).attr('href', href);

                                location.href = jQuery(this).attr('href');

                            },

                            'error': function(){

                                jQuery(this).attr('href', href);

                                location.href = jQuery(this).attr('href');

                            },

                            'timeout': 750

                          });

```

View solution in original post

1 Reply

Avatar

Correct answer by
Level 3

We ran into something similar with click tracking mboxes in target.

our solution was to override the onclick and href values of the element clicked, then in the success AND error states of the click tracking call, we then created a new dom a tag on the fly, added the href back for the next piece of js to use the window.location change.

works well, kinda hacky, but that's what we had to do in order to deal with the window.location changes

better way is to not do the window.replace and instead rely on native browser element functionality for changing the location. depends on your setup. we aren't on a SPA site with angular, but we have a lot of ajaxy reqs.

``` code

var clickTrack = function(click){

                          adobe.target.trackEvent({

                            'mbox':'mboxClickTrack',

                            'preventDefault': true,

                            'params': {

                                'menuClick': click

                            },

                            'success': function(){

                                jQuery(this).attr('href', href);

                                location.href = jQuery(this).attr('href');

                            },

                            'error': function(){

                                jQuery(this).attr('href', href);

                                location.href = jQuery(this).attr('href');

                            },

                            'timeout': 750

                          });

```