As announced last week there is now a Matomo Tag Manager available which integrates into Matomo and eventually will be directly shipped with Matomo.

It would be great if you could offer an easy way for users to embed their Tag Manager containers. We have written a guide that helps on how to write an integration plugin:
https://developer.matomo.org/guides/tagmanager/integration-plugin

Please let me know if there are any questions. Happy to improve the guide and making integrations as easy as possible.

Issue fork matomo-2978703

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tsteur created an issue. See original summary.

hass’s picture

Version: 8.x-1.4 » 8.x-1.x-dev
Component: User interface » Code
hass’s picture

Please share a patch.

pefferen’s picture

Possibly the data layer module is usefull within this context https://www.drupal.org/project/dataLayer

ricovandevin’s picture

Assigned: Unassigned » ricovandevin

I will give this a try.

ricovandevin’s picture

Attaching patch file from merge request opened in #6.

ricovandevin’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 7: matomo-support-matomo-tag-manager-2978703-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ricovandevin’s picture

StatusFileSize
new10.21 KB

Just updated the patch format.

ricovandevin’s picture

Reroll...

grimreaper’s picture

Hello,

From what I see in the linked documentation page https://developer.matomo.org/guides/tagmanager/integration-plugin, and I suppose it is like Google Tag Manager https://www.drupal.org/project/google_tag, you can have multiple tag containers per website.

So I think it should be a dedicated config entities to be able to instanciate as many containers as you want.

And maybe it should be a sub-module or separate project.

somersoft’s picture

Rerolled patch #11 so that it can be applied to 1.14 tag

stBorchert made their first commit to this issue’s fork.

stborchert’s picture

Assigned: ricovandevin » Unassigned
Status: Needs work » Needs review

Hey.
I've created another merge request using config entities for the containers as suggested by @Grimreaper.

zcht’s picture

Thanks for the patch #16, works great, the submodule installs, configures, tag manager in matomo functional. tags, triggers and events are detected correctly. tested with drupal 9.2.x and matomo 4.6.2

RTBC ++

zcht’s picture

Last update of the patch unfortunately breaks the function of the submodule because in the path /js is missing.

It is not generic in that case: Drupal Matomo configuration asks for the base directory, Matomo itself in Tag Manager settings has the following as a hint at the destination field.

The URL of your Matomo instance. It should not contain "/index.php" or "piwik.php". The URL of your current Matomo URL instance is preconfigured.

Default: //domain.tld

Saving the Matomo configuration under Drupal does not happen, the following is displayed:

The validation of "https://domain.tld/js/matomo.php" failed with an exception "Client error: `GET https://domain.tld/js/matomo.php` resulted in a `404 Not Found` response: <html> <head><title>404 Not Found</title></head> <body> <center><h1>404 Not Found</h1></center> <hr><center>nginx</c (truncated...) " (HTTP code 404).

In the Matomo documentation a snippet example is brought, there the /js is also included: https://developer.matomo.org/guides/tagmanager/integration-plugin

I have a self hosted Matomo instance, so there the path syntax with /js is expected, with a cloud Matomo this is apparently not needed.

There remain as two options with the current state of the patch:

Variant 1. Set the path to the Matomo instance via settings.php:
$config['matomo.settings']['url_https'] = 'https://domain.tld/js';

Variant 2. URL rewrite on the server to insert a /js for self hosted instance.

I think better would be here, an option field: as default is self hosted Matomo selected, as a second variant Cloud-Matomo where then the URL is output without /js

grimreaper’s picture

Status: Needs review » Needs work

Hello,

After reading quickly the last comment, is it related to #3130324: Use "js/" instead of "matomo.js"?

stborchert’s picture

Status: Needs work » Needs review

@Grimreaper Yes, I think the problem here is strongly related to #3130324: Use "js/" instead of "matomo.js". Self-hosted versions of Matomo required the path including "/js" while the cloud-hosted version doesn't use it in its paths.

The latest version of my merge request contains a new setting (unfortunately without an UI) that allows you to set a custom path that is appended to the configured URL (e.g. "/js/").

dydave’s picture

Adding related ticket.
Thanks a lot for the work on this new feature.

grimreaper’s picture

Assigned: Unassigned » grimreaper
grimreaper’s picture

@stborchert,

Thanks for the MR.

Only code organisation comments.

I will test the MR.

grimreaper’s picture

Status: Needs review » Needs work

It is working great! (although not tested with Matomo Cloud)

I will try to add a form to be able to administer the new setting.

And fix code review comments.

grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Needs work » Needs review

Form to administer the setting done. I have also done some code quality tool inspection.

Only 2 code review comments remaining!

Thanks for your feedbacks

grimreaper’s picture

Hi,

Thanks @stBorchert for the reply in my code review.

Can you please reply to my reply so I can make the last adjustment and merge it?

Also do not hesitate to post a comment after doing code review because code review comments/new commits pushed do not trigger a notification to people following issues.

grimreaper’s picture

Assigned: Unassigned » grimreaper

Thanks for the reply.

I will also do https://www.drupal.org/node/3201242

grimreaper’s picture

Finally there is nothing to do with this core change record because it only concerns content entities.

Pushing last commit. I will do a manual merge and will redo the commit for proper credit attribution.

  • Grimreaper committed 78f1541 on 8.x-1.x authored by stBorchert
    Issue #2978703 by stBorchert, ricovandevin, Grimreaper, somersoft, zcht...
  • Grimreaper committed 8807c55 on 8.x-1.x
    Issue #2978703 by stBorchert, ricovandevin, Grimreaper, somersoft, zcht...
grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Needs review » Fixed

Merged.

Thanks everyone!

  • Grimreaper committed e355421 on 8.x-1.x
    Issue #2978703 by stBorchert, ricovandevin, Grimreaper, somersoft, zcht...
grimreaper’s picture

Hello,

In #3267827: Matomo Tag Manager support Matomo cloud, I will convert container ID into container URL for easier usage of either self hosted or cloud Matomo versions.

Feedbacks welcomed!

Waiting one week before merging.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

noopal’s picture

Hi can you provide screenshot of which URL?
I have the container ID but dont know where to find URL? Thanks