> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://support.consentmo.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# 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:

```javascript
<script id="consentmo-customcode-integration">
  let isCustomCodeExecuted = false;
  function executeCustomCode() {
    if (!isCustomCodeExecuted) {
      // // The content of your CustomCode script goes here

      isCustomCodeExecuted = true;
    }
  }

  document.addEventListener('consentmoSignal_onLoad', function(eventData) {
    const csmLoadSignal = eventData.detail || { isActive: false };
    if (!csmLoadSignal.isActive) {
      executeCustomCode();
    } else {
      document.addEventListener('consentmoSignal', function(event) {
        const csmSignal = event.detail;
        const csmPreferences = csmSignal.preferences;
        if (csmPreferences.analytics && csmPreferences.marketing && csmPreferences.functionality) {
          executeCustomCode();
        }
      });
    }
  });
</script>
```

You can now proceed to add your code by replacing the line **"// ADD YOUR CUSTOM 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:

1. Navigate to your  **theme.liquid** file. You can do this by navigating to **Online Store > Themes > Actions > Edit code > theme.liquid**.

3. Locate the **<head>** tag. It is at the very beginning of the file.

5. 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](mailto: 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: ** ${color}[#476DA5](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](/en/article/uninstalling-the-consentmo-app-1t7juar/)f our FAQ page.)