DOM Ready JavaScript Extensions & Isolation

Gold Contributor
Gold Contributor

This isn't so much of a question as it is an observation, work around, and suggestion.

Let's say I have two extensions.

Extension A: A contains a condition which returns false.
Extension B: This extension isn't executing at all.

Extension B is error free and properly scoped, so why isn't it executing?! The answer is because A & B are really in the same function, so returning false exists from the function, before B is ever executed.

You could argue, correctly, that I shouldn't return false from the extension. And I rewrote my code so that I didn't. But it still seems like extensions should be a little more isolated. Extension B should run regardless of what happens in Extension A - be it return false or a JavaScript error.

So I guess my suggestion would be to do just that. Find a way to isolate the extensions from one another.

Has anyone seen anything similar or have any other feedback.

5 REPLIES 5

DOM Ready JavaScript Extensions & Isolation

Employee Emeritus

If you "return false" in an Extension scoped to a Tag then it will stop all subsequent Extensions scoped to that tag from running and ultimately stop the tracking event itself (for that tag.) This is a feature that allows you to stop the tracking for a specific scenario.

// stop tracking for a specific value in the data layer
if (b.event_type == "private") return false;

A similar feature in Web Analytics might be setting the "s.abort" feature in SiteCatalyst:

http://microsite.omniture.com/t2/help/en_US/sc/implement/abort.html

With "return false" feature, Tealium is effectively giving you this same functionality for all tags in the Tealium Marketplace.

DOM Ready JavaScript Extensions & Isolation

Gold Contributor
Gold Contributor
I understand that. For DOM ready extensions, however, since they aren't really scoped to the tag but to the DOM, I feel like it should only affect what's inside that extension.

DOM Ready JavaScript Extensions & Isolation

Employee Emeritus
I see, you're saying "return false or a JavaScript error." Using the return false probably doesn't make sense here (when Extension is scoped to DOM Ready). For JavaScript errors, a JS Extension scoped to DOM Ready is wrapped in its own try-catch block. There is some isolation that comes built-in with respect to potential JS errors.

DOM Ready JavaScript Extensions & Isolation

Gold Contributor
Gold Contributor

Right you are about the try catch. Not sure how I missed that. So errors wouldn't cause any issue. In that case this isn't nearly as big of a deal :)

 

The benefit to having separate functions would be that return false is a natural way to prevent the rest of the code in a block from executing. It's easy to write around and not use return false, but having that extra layer of protection may help save a few careless mistakes.

DOM Ready JavaScript Extensions & Isolation

Employee Emeritus

In terms of a workaround, this may be an option

// wrap in anonymous function to allow for return false in code
(function(){
utag.DB("DOM Ready Extension");
return false;
})();

Public