Adding GTM or Facebook Pixel code to header

How do you add Google Tag Manager or Facebook Pixel code to the header of a website? Chunk? Snippet?

Such things indeed typically go into the template or a header/footer chunk called in the template.

Wouldn’t necessarily look at snippets in this context - the HTML code is static so there’s no need to do any processing to it beyond just pasting it in.

I tried to insert Facebook Pixel via snippet like this … Unfortunately, it doesn’t work like this (

<?php $head_tag = ""; $facebook_fbpixel = $modx->getOption('facebook.fbpixel'); if(!empty($facebook_fbpixel)) { $chunk_data = array('fbpixel' => $facebook_fbpixel); $head_tag = $modx->getChunk('FBPixel', $chunk_data); } return $head_tag;

You don’t need to use a snippet since you just need to insert the JS into the chunk you’re using for the head or the template itself. There’s no need to code anything.

what’s the best solution for using facebook’s new CAPI to connect the pixel on server level alongside the browser?

To connect to APIs, it may make sense to use a snippet or just JS depending on what the API recommends in terms of connection. I’m personally not familiar with the API.