Documentation menuContent management systems: TYPO3

Content management systems

Add Loogika to TYPO3

A TYPO3 sitepackage builds the head of the page from TypoScript, not from an HTML template. You add Loogika as a page.includeJS entry in the setup.typoscript file of your sitepackage. After you flush the TYPO3 caches, the script loads on the pages that the page object renders.

Last updated .

What do you need before you start?

Copy your site ID from Site Settings in Loogika, under the Tracking Script tab. The site ID is the 12-character value after siteId= in the script address:

https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID

How do you add Loogika with TypoScript?

Add the script address to the page object in your main TypoScript setup file. That file is usually Configuration/TypoScript/setup.typoscript inside your sitepackage, and it already contains the line page = PAGE. A TypoScript record in the backend can hold the same code instead.

page = PAGE
page {
  includeJS {
    loogika = https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID
    loogika.defer = 1
  }
}

Replace YOUR_SITE_ID, deploy the sitepackage and flush the TYPO3 caches.

The Loogika script carries the site ID in its address, so it needs no data attribute. TYPO3 supports extra attributes on a single includeJS entry only from version 12.1. The setup above therefore works on every supported TYPO3 version.

How do you track only the production site?

Wrap the entry in an applicationContext condition. The script then loads only when TYPO3 runs in the Production context:

[applicationContext == "Production"]
page.includeJS.loogika = https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID
page.includeJS.loogika.defer = 1
[END]

TYPO3 reads the context from the TYPO3_CONTEXT environment variable. Without that variable, TYPO3 treats the installation as Production and loads the script everywhere. Set the variable on your development and staging servers if the condition seems to have no effect.

How do you keep the site ID out of the setup file?

Store the site ID as a TypoScript constant. You can then commit the setup file without values that belong to one site. Put the constant in constants.typoscript or in a TypoScript record:

# constants.typoscript
loogika {
  siteId = YOUR_SITE_ID
}

# setup.typoscript
page.includeJS.loogika = https://app.loogika.com/api/script.js?siteId={$loogika.siteId}
page.includeJS.loogika.defer = 1

How do you check that Loogika is installed?

Visit your site in another browser tab and open a few pages. Loogika's dashboard shows those pageviews within a few seconds. If nothing arrives, check whether the page source contains script.js?siteId=.

Why is the script missing from the TYPO3 page source?

A cached page is the first thing to rule out. TYPO3 caches rendered pages, so flush the caches after every TypoScript change. Use the backend toolbar or run vendor/bin/typo3 cache:flush.

The second cause is a different TypoScript file that also defines page. Open the TypoScript object browser in the backend and look at the resulting page.includeJS. The object browser shows which definition wins.