- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
I see that utage.view() has to optional arguements, a data_object and a callback function. However, I don't see the callback function executed if the data_object is empty.
This call does not log anything.
utag.view(function(){console.log('I am in the callback')})
This call does log, "I am in the callback"
utag.view({}, function(){console.log('I am in the callback')})
Is this behavior a bug or desired behavior?
Solved! Go to Solution.
Look at the signature of the utag.view() function (https://community.tealiumiq.com/t5/JavaScript-utag-js/Page-Tracking/ta-p/15563):
utag.view(data_object, callback, [uid_array]);
In your first example you pass the function as the data object and not as the callback.
11-28-2018 07:08 AM - edited 11-29-2018 12:56 AM
@TroyP - it's true that some JS libraries and newer features (thinking of Promises) will do type-based argument checks like you seem to be expecting, which allows developers to omit (preceding) optional arguments completely but still pass a callback.
utag.view()
doesn't do that - if you want to omit the first argument but send the second, you need to put a falsey placeholder in for the first:
utag.view(null, function callback(){console.log("Callback fired");});
That same principle also holds true for other utag
functions with optional arguments, to the best of my knowledge.
Hope that helps?
Best, Caleb
Copyright All Rights Reserved © 2008-2023