Content management systems
Add Loogika to Drupal
You add Loogika to Drupal through your theme. Copy the html.html.twig template from Drupal core into the templates folder of your theme, and paste the Loogika tag before the closing head tag. Clear the Drupal caches afterwards, and the script loads on the pages that theme renders.
Last updated .
What do you need before you start?
Copy your script tag from Site Settings in Loogika, under the Tracking Script tab. It looks like this, with your own site ID in place of YOUR_SITE_ID:
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
You also need access to the files of your Drupal theme, because the tag goes into a template file.
How do you add Loogika to a Drupal theme?
Override the template that prints the <head> of every page. Drupal core keeps that template in core/modules/system/templates/html.html.twig. Edit a copy inside your own theme and leave the core file as it is.
- Take
core/modules/system/templates/html.html.twigand copy it to thetemplatesfolder of your theme. - Open the copy and paste the tag just before
</head>, as shown below. - Clear the Drupal caches so that Drupal picks up the new template.
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>
How do you clear the Drupal cache?
Run drush cr on the command line. In the admin interface, go to Configuration, then Development, then Performance, and click Clear all caches.
Drupal serves pages from its page cache. A page that was cached before your change keeps the old head until you clear the caches.
How do you check that Loogika is installed?
Open your site in another tab and visit a few pages. The pageviews show up in the Loogika dashboard within a few seconds.
If nothing arrives, open the page source and look for script.js?siteId=. A missing tag can mean that the page came from the cache, so clear the caches once more. When the tag is on the page and the dashboard is still empty, work through the script troubleshooting page.