The Mautic documentation regarding the tracking snippet specifically states:

Insert following code at the end of the web page before ending </body> tag.

Perhaps there is a specific reason you are adding the snippet to the html_head, but for performance and possibly tracking functionality reasons there should be an option as the Mautic documentation suggests to place the snippet at the bottom of the page. Adding a configuration option to select placing the Mautic snippet in the footer region instead of the head would be a useful addition to this module's functionality.

Comments

sk33lz created an issue. See original summary.

sk33lz’s picture

Issue summary: View changes
jeremyr’s picture

The Mautic docs suggest putting the script in the footer because it's a best practice, and often for performance reasons.

I suspect the reasoning for adding it to the header is because the tracking script is generated by the module, as opposed to being a static file. It's apparently not as simple to attach inline JS to the footer as one would think.

If it were a file it could be defined as a library and then added to the page differently. Has anyone seen a better way to accomplish this, or can provide a patch to move it?

dioni’s picture

StatusFileSize
new2.98 KB

Hi,

I created a patch as 'first approach'. Having it as a js file is also easier to be disabled for other modules like eu_cookie_compliance.

dioni’s picture

Status: Active » Needs review
lukassykora’s picture

Status: Needs review » Active

Hi, I really like the patch, but it seems it does not provide the functionality that is desired in the title: 'Add setting to move snippet to footer region'. I could not find any setting (header or footer). Maybe it would need to extend the mautic.libraries.yml to something like:

mautic-header:
  header: true
  version: 1.0
  js:
    js/mautic.js: {}
mautic-footer:
  version: 1.0
  js:
    js/mautic.js: {}

And then add the right library based on the setting.

lukassykora’s picture

Status: Active » Needs review
StatusFileSize
new10.07 KB

I added settings for header/footer and automated tests. Please, could you review?

dioni’s picture

Hi lukassykora,

I have tested it and it works fine :) !

lukassykora’s picture

Status: Needs review » Fixed
lukassykora’s picture

Status: Fixed » Closed (fixed)