To execute JavaScript specifically on one page of your website only, you must use the Borlabs Cookie Meta Box. This allows you to use conversion or event tracking on individual pages or other post types. Here we explain how to activate the Meta Box, how to put your code there and how to make sure that the code is only executed after your visitor has given their consent.
Activate Borlabs Cookie Meta Box
To activate the Meta Box in a post type, check the corresponding post type under Settings > Display Meta Box. If you want to use the meta box in pages, check the box for pages and if you want to use it in posts, for posts etc.
After activation, the meta box will be displayed in the selected post types. Now you can execute JavaScript or other code (HTML, shortcodes) on the page.
Store JavaScript in the Meta Box
Go to the page where you want to run the JavaScript and paste your code into the now visible meta box of Borlabs Cookie. Now the corresponding JavaScript will only be executed on this page.
How to execute JavaScript only after the visitor's consent
To execute JavaScript only when the visitor has given their consent, you must use the shortcode of the corresponding Borlabs Cookie.
For example, if you want to run code from Google Analytics on a particular page only after the visitor has agreed to the Google Analytics Cookie, go to Cookies > Statistics and open the Google Analytics Cookie settings.
Now copy the Shortcode for Google Analytics under Cookie Settings.
Go to the page where you want to execute your code. Scroll down and copy the Borlabs Cookie Shortcode into the meta box. Now you have to replace …block this… with the code you want to use (in our example Google Analytics).
In our example it looks like this:
Now the code is only executed when your visitor has agreed to the Google Analytics Cookie in the Cookie Box.