JavaScript activated on Cookie bar acceptance
This might be useful if you are adding third-party tracking codes manually or if you want to trigger something only if the customer has accepted the terms in the Cookie bar. You can do this with the following snippet of code:
You can now proceed to add your code by replacing the line "// ADD YOUR CODE HERE". Once you have the whole snippet, including your code, you can follow the below steps so you can implement it in your store:
Navigate to your theme.liquid file. You can do this by navigating to Online Store > Themes > Actions > Edit code > theme.liquid.
Locate the <head> tag. It is at the very beginning of the file.
Copy the snippet and paste it after the <head> tag.
Note: The script will fire only if the Accept button on the Cookie bar, or the Accept All in the preferences pop up are clicked. If you are looking to have your function triggered in any other condition, you can reach our support team on support@consentmo.com or from the Chat button at the bottom right corner of your browser so they can look into this for you further.
NOTE: Make sure to remove the added code before deleting the app. This way, no snippets of code will be left in your theme. For more information on what you should be aware of when deleting our app check this article of our FAQ page.
<!-- Script for executing code upon clicking on the Accept or Accept All buttons provided by the app - Consentmo GDPR -->
<script>
function addEventListenerForAcceptBtn(adittionalChecks = 0) {
if (window.isenseGDPR !== undefined) {
window.addEventListener('click', function (e) {
const isAcceptButton = e.target && typeof e.target.className === 'string' && e.target.className.indexOf('isense-cc-submit-consent') >= 0 &&
(e.target.className.indexOf('cc-btn-accept-all') >= 0 || e.target.className.indexOf('cc-allow') >= 0);
if(isAcceptButton){
// ADD YOUR CODE HERE
}
});
} else {
if (adittionalChecks > 0) {
setTimeout(function() {
addEventListenerForAcceptBtn(adittionalChecks - 1);
}, 500);
}
}
}
addEventListenerForAcceptBtn(40);
</script>
You can now proceed to add your code by replacing the line "// ADD YOUR CODE HERE". Once you have the whole snippet, including your code, you can follow the below steps so you can implement it in your store:
Navigate to your theme.liquid file. You can do this by navigating to Online Store > Themes > Actions > Edit code > theme.liquid.
Locate the <head> tag. It is at the very beginning of the file.
Copy the snippet and paste it after the <head> tag.
Note: The script will fire only if the Accept button on the Cookie bar, or the Accept All in the preferences pop up are clicked. If you are looking to have your function triggered in any other condition, you can reach our support team on support@consentmo.com or from the Chat button at the bottom right corner of your browser so they can look into this for you further.
NOTE: Make sure to remove the added code before deleting the app. This way, no snippets of code will be left in your theme. For more information on what you should be aware of when deleting our app check this article of our FAQ page.
Updated on: 27/08/2024
Thank you!