Skip to main content
All CollectionsDigistorm WebsitesGlobals
How to implement tracking on your Craft 4 website
How to implement tracking on your Craft 4 website
Ben Hare avatar
Written by Ben Hare
Updated over 6 months ago

Adding tracking to every page:

To add a Meta Pixel (such as Facebook Pixel, Google Analytics 4 or other tracking codes) to every page of a Craft 4 website, follow these steps:

  • Locate the module named “Globals” on the left hand side of your CMS. This is the module of your website that controls elements like; default banners, content that appears in headers and footers, quick links, and form email responses.

  • From Globals, you will then click on “Global code” as per the screenshot below:

**Insert the Meta Pixel code:** in the “head code” field within this main template file, find the closing `<head>` tag (`</head>`) or just before the closing `<body>` tag (`</body>`). Insert the Meta Pixel tracking code provided by the platform (Facebook Pixel, Google Analytics, etc.) in the appropriate location.

For example, for Facebook Pixel:

```html   <!-- Facebook Pixel Code -->   <script>     !function(f,b,e,v,n,t,s)     {if(f.fbq)return;n=f.fbq=function(){n.callMethod?     n.callMethod.apply(n,arguments):n.queue.push(arguments)};     if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';     n.queue=[];t=b.createElement(e);t.async=!0;     t.src=v;s=b.getElementsByTagName(e)[0];     s.parentNode.insertBefore(t,s)}(window, document,'script',     'https://connect.facebook.net/en_US/fbevents.js');     fbq('init', 'YOUR_PIXEL_ID');     fbq('track', 'PageView');   </script>   <noscript>     <img height="1" width="1" style="display:none"          src="https://www.facebook.com/tr?id=YOUR_PIXEL_ID&ev=PageView&noscript=1"/>   </noscript>   <!-- End Facebook Pixel Code -->   ```

Replace `'YOUR_PIXEL_ID'` with your actual Pixel ID provided by Facebook or the respective platform.

  • **Save the changes:** by clicking on the save button on the top right.

  • **Clear cache and test:** Clear any caches if your Craft 4 website uses caching mechanisms. Then, visit different pages of your website to verify that the Meta Pixel code is present in the source code of each page.

For Google Analytics 4:

Go to your Google account, to get your Google tag.

Copy your code into your Craft CMS Globals.

Tracking a specific page:

Notes: If you would like to add a campaign code to an individual page, and not the entire website as per instructions above, you can do so by adding an embed type content block to the bottom of the page you are aiming to track. You can paste the Raw HTML code there and the campaign will start tracking on that page/entry only.

Did this answer your question?