{"id":23123350,"url":"https://github.com/openmost/datalayer-sync","last_synced_at":"2026-03-20T00:41:00.635Z","repository":{"id":164461940,"uuid":"639907155","full_name":"openmost/datalayer-sync","owner":"openmost","description":"Syncronise your Google Analytics and Matomo dataLayers","archived":false,"fork":false,"pushed_at":"2024-12-16T14:54:56.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-04T04:27:09.673Z","etag":null,"topics":["datalayer","google-analytics","matomo"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openmost.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-12T13:52:08.000Z","updated_at":"2024-12-16T14:55:05.000Z","dependencies_parsed_at":"2025-04-04T04:25:39.999Z","dependency_job_id":"e35d0a92-8c8f-4730-aa18-44482fa5d3b9","html_url":"https://github.com/openmost/datalayer-sync","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/openmost/datalayer-sync","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openmost%2Fdatalayer-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openmost%2Fdatalayer-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openmost%2Fdatalayer-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openmost%2Fdatalayer-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openmost","download_url":"https://codeload.github.com/openmost/datalayer-sync/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openmost%2Fdatalayer-sync/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28473974,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-15T22:27:41.514Z","status":"ssl_error","status_checked_at":"2026-01-15T21:54:47.910Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datalayer","google-analytics","matomo"],"created_at":"2024-12-17T07:33:44.882Z","updated_at":"2026-01-15T23:02:07.837Z","avatar_url":"https://github.com/openmost.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# Synchronize Google Tag Manager and Matomo data layers (```dataLayer``` and ```_mtm```)\r\n\r\n\r\n\u003e [!IMPORTANT]\r\n\u003e This code is now part of Matomo 5.2.0 and above ! 🥳\r\n\u003e\r\n\u003e If you want to enable this feature in your container, edit your container and activate \"Actively synchronise from the Google Tag Manager data layer\".\r\n\r\n## The problem (only for Matomo \u003c 5.2.0)\r\nMany websites have both Google Tag Manager and Matomo Tag Manager implemented on their source code.\r\nTo get similar events on Google Analytics and Matomo, the two Tag Managers have to share a common ```dataLayer```.\r\n\r\nMatomo is compatible with GTM data layer only with data present in ```dataLayer``` array before page load.\r\nEvery event or data pushed to the dataLayer after the page load **will not** be detected by Matomo Tag Manager.\r\n\r\n\r\n## The solution\r\nTo keep Matomo up to date with the dataLayer content, we have to synchronize GTM ```dataLayer``` with Matomo ```_mtm```.\r\nThis code listen for every ```push()``` in Google dataLayer, pick the latest item pushed in ```dataLayer```, and push this item to ```_mtm``` data layer.\r\n\r\n**You can copy this code and past it in a custom HTML tag triggered on every page view in Matomo Tag Manager.**\r\n\r\nENJOY !\r\n\r\n```html\r\n\u003cscript\u003e\r\nwindow.dataLayer = window.dataLayer || [];\r\nwindow._mtm = window._mtm || [];\r\nlet syncDataLayer = function(array, callback) {\r\n    array.push = function(e) {\r\n        Array.prototype.push.call(array, e);\r\n        callback(array);\r\n    };\r\n};\r\n\r\nsyncDataLayer(window.dataLayer, function(e) {\r\n    window._mtm.push(window.dataLayer[window.dataLayer.length-1]);\r\n});\r\n\u003c/script\u003e\r\n```\r\n\r\nA demo is available in ```index.html``` file on this project, you just have to look on the console for empty ```_mtm```, click the button to push event and data, and see the magic !\r\n\r\n\u003c!--\r\n## Optional : Completely remove Google Tag Manager\r\nIn some cases, you want to keep the dataLayer but completely remove the Google Tag Manager tracking code. You can remove the code, but you must keep the initialization of ```dataLayer```.\r\n\r\nReplace the Google Tag Manager code with this simple initialization code.\r\n\r\n```html\r\n\u003cscript\u003e\r\n // Initialize GTM dataLayer to keep dataLayer working \r\n window.dataLayer = window.dataLayer || [];\r\n\u003c/script\u003e\r\n```\r\n--\u003e\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenmost%2Fdatalayer-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenmost%2Fdatalayer-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenmost%2Fdatalayer-sync/lists"}