Virtualmin analytics: javascript for head section

Virtualmin → Logs and Reports → Analytics Accounts

Content meant to be placed under head section is getting placed under header section instead.

For example, see source code for https://fb.sumu.uk

Update 1:

Update 2:

screenshot of source code

Thats for adding Javascript not css links, just had a read of the heading.

@bislinks

  • how did you get this feature, the menu item is missing in my virtualmin
  • maybe the regex needs a little tweaking
  • did you get this to work or did you change how you did things

@stefan1959

  • Although this says it is for javascript I bet it works fine for CSS. (if it put it in the right place)
1 Like

I would not use this plugin. Virtualmin should only be use to serve the website and not manipulate it. The plugin might not be maintained anymore.

I think I recommend against using this plugin. It depends on mod_perl, which is already a pretty ugly start. And, it hasn’t been maintained for a while; I don’t expect it to work with current versions of the analytics tools it supports, and I wouldn’t be surprised if it breaks other stuff.

We would have updated it if there were some good way to interact with various web apps and stuff, but there really isn’t. Apps need to do it themselves, basically, as it’s not generally safe for us to munge their output like this (even if there were good ways to do it other than mod_perl or some other Apache module).

4 Likes

Is your recommendation against just the javascript for head and body sections part or for the whole analytics plugin?

I think this answers the question

1 Like

It was created in a time when there were still lots of websites that were just plain old HTML. Web apps ought to handle it themselves, and the vast majority of web apps have some kind of support for it, or you can insert the code into the header template or whatever. These days, every app downloads a gajillion lines of JavaScript before it even starts doing anything, and analytics is just another gajillion lines of JavaScript to download at the same time.

Also, back then, everybody was already bloating up Apache with mod_php and a bunch of other stuff, so adding mod_perl wasn’t that big of an extra ask (fun fact, PHP was originally written in Perl and ran in mod_perl). mod_perl is still actively maintained and I know lots of folks are still running it in production (I see it mentioned in Perl jobs listings all the time), but I wouldn’t want to build a new deployment that relies on it, even if I were deploying Perl web applications. It’s slightly less of a code smell than deploying with mod_php, but only slightly, and there are definitely better (more secure, probably lighter, probably faster) ways to run applications…the problem is none of those ways has any way to modify the HTML just as it’s being served by Apache (which is what the Virtualmin Analytics module does). It takes an Apache module to do that, and mod_perl is the easiest way for a Perl developer to make an Apache module.

But, your apps can do it themselves quite easily, in the vast majority of cases.

I see an option for GA and Piwik in the screenshot. This might let you append to the head quite easily. Even if you don’t use the plugin, you could manually integrate GA or Piwik to your website.

Piwik is now Motamo. It has a Tag Manager, as does Google Analytics. You could then use the Tag Manager to append to the header section of the html.

This solution does not involve Virtualmin at all, if you don’t use the plugin.