I have multiple libraries in launch and one of them must load first than the others. Is this possible? If not, how is the loading order of the libraries defined, by creation date?
Best regards
Solved! Go to Solution.
Views
Replies
Total Likes
You can use like the below, here you can manage multiple launch codes and website domains based on your requirements
<script type="text/javascript">
var EST_Hostname = location.hostname;
if(EST_Hostname.match(/^(?:www\.)?domain*\.(com|in|net|co)(\.in)*/))
{
document.write(unescape("%3Cscript src='//assets.adobedtm.com/launch-XXXXXXX-XXXXXXXXXXXXXXXXXXX.min.js' type='text/javascript'%3E%3C/script%3E"));
}
else if(EST_Hostname.match(/^(?:www\.)?domain1*\.(com|in|net|co)(\.in)*/))
{
document.write(unescape("%3Cscript src='//assets.adobedtm.com/launch-XXXXXXX-XXXXXXXXXXXXXXXXXXX.min.js' type='text/javascript'%3E%3C/script%3E"));
}
else if(EST_Hostname.match(/^(?:www\.)?domain2*\.(com|in|net|co)(\.in)*/))
{
document.write(unescape("%3Cscript src='//assets.adobedtm.com/launch-XXXXXXX-XXXXXXXXXXXXXXXXXXX.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
@JassonAlgo Could you elaborate bit more on how the libraries are structured? Are they all in one rule with multiple action? If yes this can be done using rule component sequencing
You also have an option of using "JS Promises" in custom code, if this helps your use case.
Hope that helps
Views
Replies
Total Likes
You can't load one library followed by another library. A library is a collection of items (rules, data elements, extensions) that have been "packaged up" to load into a specific environment.
Sidenote: as you may have noticed, you can load only one library in a development or staging environment at any one time. You can't have more than one library loaded into an environment.
@Anil_Umachigi gives a good suggestion of ordering your rules in the sequence that you desire or using Promises.
Hi @JassonAlgo ,
I'm assuming multiple libraries in Launch mean multiple 3rd party vendor libraries in Launch.
You are looking to load these 3rd party libraries in a specific order.
If that's the case, @Anil_Umachigi 's response is probably the best way to ensure that loads.
How I do it is using JS Promises by doing a check and timeout that checks if the library has loaded.
Let's take the Facbeook pixel for example.
I would set up a promise that will:
1. Load the Facebook library
2. Check in the promise if "fbq" is available and put it in a timeout loop (let's say 2 seconds)
3. And then move on to the next item.
Not tested below but just an idea of how you can potentially do it. You would add more 'then()' at the end for your next libraries.
function loadFacebookPixel() {
if (typeof fbq === 'undefined') {
return new Promise(function(resolve, reject) {
var script = document.createElement('script');
script.src='https://connect.facebook.net/en_US/fbevents.js';
script.onload = function() {
setTimeout(function() {
if (typeof fbq === 'undefined') {
reject(new Error('Facebook Pixel not available after timeout'));
} else {
resolve(fbq);
}
}, 2000);
};
script.onerror = function() {
reject(new Error('Failed to load Facebook Pixel script'));
};
document.head.appendChild(script);
});
} else {
return Promise.resolve(fbq);
}
}
// Example usage:
loadFacebookPixel().then(function(fbq) {
if (typeof fbq !== 'undefined') {
fbq('track', 'PageView');
}
}).catch(function(error) {
console.error(error);
});
You can use like the below, here you can manage multiple launch codes and website domains based on your requirements
<script type="text/javascript">
var EST_Hostname = location.hostname;
if(EST_Hostname.match(/^(?:www\.)?domain*\.(com|in|net|co)(\.in)*/))
{
document.write(unescape("%3Cscript src='//assets.adobedtm.com/launch-XXXXXXX-XXXXXXXXXXXXXXXXXXX.min.js' type='text/javascript'%3E%3C/script%3E"));
}
else if(EST_Hostname.match(/^(?:www\.)?domain1*\.(com|in|net|co)(\.in)*/))
{
document.write(unescape("%3Cscript src='//assets.adobedtm.com/launch-XXXXXXX-XXXXXXXXXXXXXXXXXXX.min.js' type='text/javascript'%3E%3C/script%3E"));
}
else if(EST_Hostname.match(/^(?:www\.)?domain2*\.(com|in|net|co)(\.in)*/))
{
document.write(unescape("%3Cscript src='//assets.adobedtm.com/launch-XXXXXXX-XXXXXXXXXXXXXXXXXXX.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
Views
Like
Replies
Views
Likes
Replies