Code Snippets
Pro Feature — Code snippets are available in the Pro and Agency tiers.
Unfold CMS allows administrators to inject custom code into specific locations on the site without editing template files. This is useful for analytics scripts, custom CSS, conversion tracking, chat widgets, and other third-party integrations.
Overview
Code snippets provide:
- Multiple injection points — Head, body start, body end
- Enable/disable toggle — Quickly turn snippets on and off
- No template editing — Add code through the admin panel
- Priority ordering — Control the order snippets render
- Built-in templates — One-click setup for Google Tag Manager, GA4, Meta Pixel, and more
Templates
The fastest way to add common tracking codes. Click Use Template on the Code Snippets page and choose from:
| Template | What You Need | Snippets Created |
|---|---|---|
| Google Tag Manager | Container ID (GTM-XXXXXXX) |
2 — head script + body noscript |
| Google Analytics 4 | Measurement ID (G-XXXXXXXXXX) |
1 — head script |
| Meta / Facebook Pixel | Pixel ID (numeric) | 1 — head script |
| Crisp Chat | Website ID (UUID) | 1 — body end script |
| Custom CSS | Nothing | 1 — empty style block |
| Custom JavaScript | Nothing | 1 — empty script block |
Using a Template
- Navigate to Marketing > Code Snippets
- Click Use Template
- Select a template from the grid
- For templates that require an ID, enter the value and click Create
- For Custom CSS / Custom JavaScript, the snippet is created immediately
Templates create fully configured snippets with the correct position, type, and zones. You can edit them afterwards like any other snippet.
Google Tag Manager
GTM requires two snippets — one in the <head> and one right after <body>. The GTM template creates both automatically. You can find your Container ID at tagmanager.google.com under Admin > Container Settings.
Google Analytics 4
Tip: For simple GA4 tracking, you can also use Settings > General > Google Analytics 4 which only requires your Measurement ID. The Code Snippets template is useful when you need custom GA4 configuration.
Find your Measurement ID at analytics.google.com under Admin > Data Streams.
Creating Snippets Manually
Navigate to Marketing > Code Snippets and click Add Snippet.
Snippet Fields
| Field | Description |
|---|---|
| Name | Internal identifier (e.g., "Google Analytics") |
| Type | Script, style, meta, or HTML |
| Position | Where the code is injected |
| Zones | Which pages the snippet applies to |
| Content | The HTML, CSS, or JavaScript code |
| Active | Whether the snippet is currently enabled |
| Priority | Render order (lower number = rendered first) |
Injection Positions
| Position | Placement | Common Use |
|---|---|---|
| Head | Inside <head> before </head> |
Analytics, meta tags, CSS |
| Body Start | After <body> tag |
GTM noscript, tracking pixels |
| Body End | Before </body> tag |
Chat widgets, deferred scripts |
Zones
| Zone | Description |
|---|---|
| All Pages | Every public page on the site |
| Public | Public website pages only |
| Auth | Login, register, password reset pages |
Best Practices
- Use templates when possible — They generate correct code with proper positions
- Use descriptive names — "Google Analytics 4" is better than "Script 1"
- Choose the right position — Analytics in Head, widgets in Body End
- Test after adding — Verify the snippet works and doesn't break the site
- Disable instead of deleting — Toggle off snippets you might need later
- Minimize head scripts — Too many head scripts slow down page load
Security
Code snippets are only editable by administrators. The content is rendered as-is (unescaped), so ensure you trust any code before adding it.
Warning: Only add code from trusted sources. Malicious scripts can compromise your site and visitors.
Related
- Analytics — Built-in Google Analytics dashboard integration (Pro)
- Announcements — Visual announcement banners