A Guide to Code Injection: Custom Code Implementation for Websites

By Michael Turner

December 12, 2024 at 02:51 PM

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

Basic Usage

Code injection allows you to add:

  • Live chat services
  • Domain verification code
  • Analytics tracking
  • Third-party integrations

Note: Code injection is not for content or styling - use Pages for content and CSS Editor for styles.

Implementation Guidelines

  • JavaScript code must be enclosed in
    <script>
    tags
  • CSS code should go in the CSS Editor (if using injection, enclose in
    <style>
    tags)
  • Ajax loading may affect CSS in code injection
  • Checkout pages don't support code injection

Adding Code

  1. Access the Code Injection panel
  2. Add HTML/scripts to appropriate sections:
    • Header (inside
      <head>
      tag)
    • Footer (before closing
      </body>
      tag)
    • Page-specific areas
    • Order confirmation/status pages
  3. Click Save

Cookie Banner Integration

For third-party integrations:

  1. Enable Cookie Banner in Visitor Cookie and Data panel
  2. Select "Accept and Reject" banner type
  3. Modify integration code to respect visitor consent

Available Injection Areas

  • Header
  • Footer
  • Lock Screen
  • Order Confirmation Page
  • Order Status Page
  • Page-specific locations

Squarespace Migration Notification

Squarespace Migration Notification

Order Status Tags

Use these tags to display order information:

  • {orderId}
  • {orderSubtotal}
  • {orderSubtotalCents}
  • {orderGrandTotal}
  • {orderGrandTotalCents}
  • {customerEmailAddress}

Troubleshooting

If code causes editing issues:

  1. Use the "Disable scripts in preview" option
  2. Test in incognito/private window
  3. Add "/safe" to your editing URL if needed

For best results, follow official documentation and consider consulting a Squarespace Expert for complex implementations.

Related Articles

Previous Articles