Highlighted

Launching a Tag based on a JS variable set in a JS Extension

Silver Contributor
Silver Contributor
We are working on the load rules for a SiteCatalyst Tag and we want it to be launched based on the value of a Javascript variable defined in a Javascript Code Extension that is launched as a Pre Loader. As you can see in the following code lines, we are defining a variable â lanzamientoâ : var iFrameTaggeo = $("iframe[class='notag']").length; if (iFrameTaggeo <= 0) lanzamiento = '1'; //If this variable is set, then, launch the SC Tag else lanzamiento = '0'; //In this case, the SC Tag shouldn't be launched The output for this extension would be "lanzamiento". Then we use the â lanzamientoâ variable in the Load Rules: lanzamiento EQUALS 1 THEN launch SiteCatalyst Tag The problem is that this is not working at all: we never get SC to be launched under this conditions. It seems that when the Load Rule condition is checked, the â lanzamientoâ variable is not defined. But once the page is loaded, if we go to the console and see if "lanzamiento" has a value, it does. Can anyone give us some advice?
2 REPLIES 2
Highlighted

Launching a Tag based on a JS variable set in a JS Extension

Employee Emeritus
It's hard to be sure without seeing a test page, but the problem here is probably down to the way you are using jQuery. In general, you can set a variable in a preloader extension and then use it in a load rule. Preloader extensions execute immediately that the utag.js file is loaded in the browser. Depending on whether you are using a synchronous or async insert, and whether the utag.js is towards the top or the bottom of the page, this might well be before the DOM Ready event, and before the iframe in question has been rendered in the DOM. You need to check also that the jQuery library has loaded before you are executing this extension. One alternative mechanism to get the same effect (without changing your html) would be load the SiteCatalyst tag on All Pages. Then create a JS Code extension scoped just to that tag, have this code in it: var iFrameTaggeo = $("iframe[class='notag']").length; if (iFrameTaggeo > 0) { return false; // do not fire tag } If you have an extension that is scoped to a specific tag, and the extension returns false, the tag will not fire.
Highlighted

Launching a Tag based on a JS variable set in a JS Extension

Employee Emeritus
One other thing to check for is how your "lanzamiento" variable is defined in the UI. According to the code above the "Type" setting should be JS Page Variable. If you have added the variable "lanzamiento" as a Data Object variable it will not be recognized and therefore your load rule condition won't be met.