How to Use Code Injection for Custom Scripts and HTML Integration

By Michael Chen

December 12, 2024 at 02:51 PM

Code injection allows you to enhance your site by adding HTML code and custom scripts. Here's how to use it effectively:

Basic Usage

Code injection lets you add various elements like messaging services, domain verification, analytics tools, and other custom functionality to your site. Note that it's not meant for content or styling - use Pages for content and Custom CSS Editor for styles.

Adding Code

To inject code:

  1. Open the Code Injection panel
  2. Add valid HTML or scripts in appropriate fields (header, footer, etc.)
  3. Click Save

JavaScript code must be wrapped in

<script>
tags, while CSS should ideally go in the Custom CSS Editor.

Key Injection Areas

Header

  • Injected into
    <head>
    tag on every page
  • Affects entire site

Footer

  • Injected before closing
    </body>
    tag
  • Appears on all pages

Lock Page

  • Displays above password field on protected pages
  • Better to use Lock Screen panel for customization

Order Confirmation & Status Pages

  • Supports customer-specific tags:
    • {orderId}
    • {orderSubtotal}
    • {orderGrandTotal}
    • {customerEmailAddress}

Malicious code injection warning

Malicious code injection warning

Page-Specific Injection

To add code to individual pages:

  1. Hover over page in Pages panel
  2. Click the settings icon
  3. Select Advanced
  4. Add code in Page Header Code Injection

Cookie Banner Integration

For third-party integrations:

  1. Enable cookie banner in Cookies and Visitor Data panel
  2. Select Accept/Reject banner type
  3. Add necessary integration code
  4. Save changes

Important Notes:

  • Disable scripts in preview when troubleshooting
  • Payment pages don't support code injection
  • Ajax loads may affect CSS in code injection
  • Blog post injection appears differently based on template version
  • Code won't appear on Index landing pages

For best results, consult documentation specific to your integration needs and test thoroughly before deployment.

Related Articles

Previous Articles