How to implement the callback function | Community
Skip to main content
MichaelWon
Level 5
July 27, 2017
Solved

How to implement the callback function

  • July 27, 2017
  • 6 replies
  • 10647 views

Hello,

Has anyone implemented the

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by andrew_r-GrfLbX

Do you mean the callback functions in AppMeasurement from v1.8.0 onwards?

Documentation on it is pretty light but it's straightforward to use. If you have a specific question ask away.

Added the following pre- and post-tracking call hooks.

  • s.registerPreTrackCallback
  • s.registerPostTrackCallback

These functions take as parameters: the callback (a function), and the parameters to that function. For example:

s.registerPreTrackCallback(function(requestUrl,a,b,c) {

console.log("pre track callback");

console.dir(requestUrl); // Request URL

console.dir(a); // param1

console.dir(b); // param2

console.dir(c); // param3 }, "param1", "param2", "param3");

The callback is invoked with the requestUrl and any parameters passed in when the callback is registered. This occurs either before or after the tracking call, depending on which method is used to register the callback. The order in which these callbacks are called is not guaranteed. Callbacks registered in the pre function are invoked after the final tracking URL is created. The post callbacks are called upon a successful tracking call (if the tracking call fails, these functions are not called). Any callback registered with registerPreTrackCallback do not affect the tracking call. Also, calling any of the tracking methods in any registered callback is not recommended and could cause an infinite loop.

6 replies

andrew_r-GrfLbX
andrew_r-GrfLbXAccepted solution
Level 5
July 27, 2017

Do you mean the callback functions in AppMeasurement from v1.8.0 onwards?

Documentation on it is pretty light but it's straightforward to use. If you have a specific question ask away.

Added the following pre- and post-tracking call hooks.

  • s.registerPreTrackCallback
  • s.registerPostTrackCallback

These functions take as parameters: the callback (a function), and the parameters to that function. For example:

s.registerPreTrackCallback(function(requestUrl,a,b,c) {

console.log("pre track callback");

console.dir(requestUrl); // Request URL

console.dir(a); // param1

console.dir(b); // param2

console.dir(c); // param3 }, "param1", "param2", "param3");

The callback is invoked with the requestUrl and any parameters passed in when the callback is registered. This occurs either before or after the tracking call, depending on which method is used to register the callback. The order in which these callbacks are called is not guaranteed. Callbacks registered in the pre function are invoked after the final tracking URL is created. The post callbacks are called upon a successful tracking call (if the tracking call fails, these functions are not called). Any callback registered with registerPreTrackCallback do not affect the tracking call. Also, calling any of the tracking methods in any registered callback is not recommended and could cause an infinite loop.

MichaelWon
Level 5
July 27, 2017

Hi Andrew,

Thanks for sharing, and I was able to find this. Can you please help with the following:

1. If I want just want to set s.clearVars(); after any server call, what does the code look like?

2. Once, we have the code where does it go?

I found/read the same article as you. Because I am a JS novice, I am unclear how and where to fire the Callback.

Thanks,

Michael

EricMatisoff
Adobe Employee
Adobe Employee
July 31, 2017

Hey michael.won@jet.com​,

I've been putting the following code into DTM via the "Customize Page Code" accordion in the AA Tool. Be sure to keep it OUTSIDE of doPlugins or you'll have a bit of a mess on your hands:

Hope that helps!

MichaelWon
Level 5
August 1, 2017

Hey Eric,

This looks to be working like a charm!! Much appreciated!

Michael

EricMatisoff
Adobe Employee
Adobe Employee
August 1, 2017

giphy.gif

Stewart_Schilling
Community Advisor
Community Advisor
April 13, 2018

@