I have a setup tag for a Tracking service called Clicky that loads asynchronously on every page. I need to access "clicky" variable from another tag, which is only accessible after setup async script finishes loading.
For that reason, my tag script looks hacky. Is there any other way to check if an async script is loaded on Tag Manager context?
<script>
function clickyGoal() {
try {
clicky.goal('Email Capture');
} catch(e) {
setTimeout(clickyGoal, 200);
}
}
clickyGoal();
</script>
EDIT: This is the main setup tag that fires on all pages.
<script type="text/javascript">
var clicky_site_ids = clicky_site_ids || [];
clicky_site_ids.push(<id-number>);
(function() {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = '//static.getclicky.com/js';
( document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0] ).appendChild( s );
})();
</script>