Adding Custom JS to an Instant Scan

The custom JS injection feature allows you to add Javascript to be executed on the page when the instant scan is run.  This can be used for a variety of purposes, including testing interactions between scripts and examining what additional tags a new tag loads without having to place it on the page. 

A few important points about using the custom JS feature:

1.  Code is injected as the first script on the page.

2. Even async code will be added as the first script on the page, which means it may be executed before anything else, including the DOM finishing loading.  It may be good idea to wrap async scripts using the`DOMContentLoaded`event to ensure it runs after the DOM finishes loading.

3. It's also safest to avoid using document.write as part of async scripts.

4. Despite the positioning on the code, it is not guaranteed to be the exact first script executed if run asynchronously since browsers load multiple parts of the page in parallel.  If you wish to ensure the injected code is run first you should use synchronous code.

Have more questions? Submit a request


Please sign in to leave a comment.