I have tried on a few different occasions to place script into index via terminal, save and then visit page. Have placed at end just before , directly after meta tags, at start of and a couple places in between. It disappears every time it seems after some tiddler creation/editing sessions. There were a couple of random registered visits then nothing. Also, I have working code on other non-related site that people have visited and clicked through that didn’t register.
Place your javascript content into the text field of a tiddler (e.g., “MatomoAnalytics”)
Give that tiddler a tag of $:/tags/RawMarkup
When you save your TiddlyWiki, the contents of the “MatomoAnalytics” tiddler will be inserted into the file “…at the bottom of the <head> section in the generated HTML file.” Then, when you reload the file, the inserted javascript content will be invoked before any of the TiddlyWiki core code is processed.
After using system a couple of weeks, and reading around forums on other things I had a sneaking suspicion that it was going to involve putting into a tiddler…
TiddlyWiki uses a template to “build” itself whenever it is saved. Since the template does not know about your external js-script it was overwritten every time you saved the wiki.
The template knows about tiddlers tagged: $:/tags/RawMarkup so it “builds” itself “placing” the tiddler content to the right place in the saved wiki.
Since “raw” markup works outside the control of the TW core code and the TW UI, it should be the exception. Used for usecases as yours.
If other 3rd party libraries should be used with TW the best way is to have them as TW plugins. – Just to let you know.