Hot answers tagged

3

By checking the code, I could find a method named getHeaders() that will return all the headers of the current request. So if you want to retrieve the content of the foo header, just use: {% set headers = craft.app.request.getHeaders() %} {% set fooHeader = headers['foo'] %}


2

Craft makes no assumptions on how your site should be built so it's impossible for us to say exactly where to put the pixel code. You would add the code to whichever template you needed it in. This depends entirely on how your site is put together. Oftentimes the <head> portion will be within your main _layout file but that is not necessarily always ...


2

This is something that is best done via server-side config. The reason is that when an image is requested, for instance, your Twig code that sets the header never gets run for that request. You can see how it is done via Nginx here: Nginx-Craft For Apache (don't use .htaccess pls) go here: html5 boilerplate apache


1

Solved it by just serving the file within a controller action like this: public function actionCacheCraftServiceWorker () { $serviceWorkerFile = Craft::getAlias('@skayo/cachecraft/assetbundles/cachecraft/dist/js/CacheCraftServiceWorker.min.js'); return Craft::$app->getResponse()->sendFile( $serviceWorkerFile, '...


1

If you're using SEOmatic for Craft3 it has a setting to add facebook pixel and various other tracking scripts. SEOmatic github


Only top voted, non community-wiki answers of a minimum length are eligible