{"id":416642,"date":"2024-12-30T08:00:00","date_gmt":"2024-12-30T08:00:00","guid":{"rendered":"https:\/\/www.weixiaoduo.com\/plugins\/datalayer\/"},"modified":"2025-04-16T23:08:00","modified_gmt":"2025-04-16T23:08:00","slug":"datalayer","status":"publish","type":"post","link":"https:\/\/www.weixiaoduo.com\/plugins\/datalayer\/","title":{"rendered":"DataLayer for GTM and Matomo"},"content":{"rendered":"<p>Elevate your website analytics with the DataLayer plugin!<br \/>\nThis robust plugin creates a fully populated and standardized dataLayer object, ensuring seamless integration with both Google Tag Manager and Matomo Tag Manager.<\/p>\n<ul>\n<li>Instant Setup: Automatically generates and populates a dataLayer object with essential website and user interaction data.<\/li>\n<li>Universal Compatibility: Works flawlessly with Google Tag Manager and Matomo Tag Manager, making it easier to manage your tagging needs.<\/li>\n<li>Customizable Data: Easily add or modify data points to fit your specific tracking requirements.<\/li>\n<li>Performance Optimized: Lightweight and optimized for speed to ensure your site remains fast and responsive.<\/li>\n<\/ul>\n<p>Get a quick look at all the generated structures!<\/p>\n<h4>Archive page `dataLayer` structure<\/h4>\n<p>Easy access to your archive data with a standard event name and subject.<\/p>\n<pre><code>{\n    \"event\": \"view_archive_date\", \/\/_date may be replaces with _tax value\n    \"page\": {\n        \"type\": \"archive\",\n        \"title\": \"january 2025 - Example\",\n        \"url\": \"https:\/\/example.com\/2025\/01\",\n        \"path\": \"2025\/01\",\n        \"locale\": \"en_US\",\n        \"archive_type\": \"date\",\n        \"taxonomy\": false,\n        \"post_type\": false,\n        \"date\": {\n            \"year\": 2025,\n            \"month\": 1,\n            \"day\": null\n        }\n    }\n}\n<\/code><\/pre>\n<h4>Author page `dataLayer` structure<\/h4>\n<p>Easy access to all author details on his archive page.<\/p>\n<pre><code>{\n    \"event\": \"view_author\",\n    \"page\": {\n        \"id\": 1,\n        \"nickname\": \"openmost\",\n        \"display_name\": \"openmost\",\n        \"first_name\": \"Ronan\",\n        \"last_name\": \"HELLO\",\n        \"description\": \"The creator of this super plugin\",\n        \"type\": \"author\",\n        \"url\": \"https:\/\/example.com\/author\/openmost\",\n        \"path\": \"author\/openmost\",\n        \"title\": \"Author: openmost\"\n    }\n}\n<\/code><\/pre>\n<h4>Error page `dataLayer` structure<\/h4>\n<p>This <code>dataLayer<\/code> structure allows you to easily track the 404 error and detect the referring page that led to this error.<br \/>\nWhat a great trick yeah?<\/p>\n<pre><code>{\n    \"event\": \"view_error_404\",\n    \"page\": {\n        \"type\": \"error\",\n        \"title\": \"Page not found - Website\",\n        \"url\": \"https:\/\/example.com\/url-that-encountered-a-404-error\",\n        \"path\": \"\/url-that-encountered-a-404-error\",\n        \"locale\": \"en_US\",\n        \"error_type\": \"404\",\n        \"http_status_code\": 404\n    }\n}\n<\/code><\/pre>\n<h4>Search results page `dataLayer` structure<\/h4>\n<p>The search key in this object allows you to get the search term and total results to detect invalid searches.<br \/>\nVery useful for Matomo Tag Manager, and nice hack for Google Tag Manager.<\/p>\n<pre><code>{\n    \"event\": \"view_search_results\",\n    \"page\": {\n        \"type\": \"search\",\n        \"url\": \"https:\/\/example.com\",\n        \"path\": \"\",\n        \"title\": \"You searched for Demo - Example\",\n        \"locale\": \"en_US\"\n    },\n    \"search\": {\n        \"search\": \"Demo\",\n        \"search_cat\": \"\",\n        \"search_count\": 3,\n        \"query\": \"Demo\",\n        \"found_posts\": 3,\n        \"post_count\": 3\n    }\n}\n<\/code><\/pre>\n<h4>Home, Post Type `dataLayer` structure (blog posts, custom post type single page)<\/h4>\n<p>The following structure is generated for a single post page, but it automatically adapts to your custom post type, page, etc.<\/p>\n<pre><code>{\n    \"event\": \"view_single_post\",\n    \"page\": {\n        \"type\": \"post\",\n        \"id\": 1,\n        \"url\": \"https:\/\/example.com\/blog\/super-article-path\",\n        \"path\": \"\/blog\/super-article-path\",\n        \"title\": \"Super article title | Example\",\n        \"locale\": \"en_US\",\n        \"is_home\": false,\n        \"is_front_page\": false,\n        \"post_name\": \"super-article-path\",\n        \"post_title\": \"Super article title\",\n        \"post_excerpt\": \"\",\n        \"post_status\": \"publish\",\n        \"post_date\": \"2024-08-17 13:30:00\",\n        \"post_date_gmt\": \"2024-08-17 13:30:00\",\n        \"post_modified\": \"2024-08-17 13:30:00\",\n        \"post_modified_gmt\": \"2024-08-17 13:30:00\",\n        \"post_type_name\": \"post\",\n        \"post_type_label\": \"Posts\",\n        \"post_type\": {\n            \"name\": \"post\",\n            \"label\": \"Posts\",\n            \"label_singular\": \"Post\",\n            \"label_plural\": \"Posts\",\n            \"description\": \"The super post type description\"\n        },\n        \"guid\": \"https:\/\/example.com\/?p=1\",\n        \"post_mime_type\": false,\n        \"comment_status\": \"open\",\n        \"comment_count\": \"0\",\n        \"author\": {\n            \"id\": 1,\n            \"nickname\": \"openmost\",\n            \"display_name\": \"openmost\",\n            \"first_name\": \"Ronan\",\n            \"last_name\": \"HELLO\",\n            \"description\": \"The creator of this super plugin\"\n        },\n        \"taxonomies\": {\n            \"category\": {\n                \"name\": \"category\",\n                \"label\": \"Categories\",\n                \"description\": \"\",\n                \"object_type\": [\n                    \"post\"\n                ],\n                \"terms\": {\n                    \"Uncategorized\": {\n                        \"term_id\": 1,\n                        \"slug\": \"uncategorized\",\n                        \"name\": \"Uncategorized\",\n                        \"term_group\": 0,\n                        \"term_taxonomy_id\": 1,\n                        \"taxonomy\": \"category\",\n                        \"description\": \"\",\n                        \"parent\": 0,\n                        \"count\": 1,\n                        \"filter\": \"raw\"\n                    }\n                },\n                \"primary_term\": [] \/\/Filled only with YoastSEO plugin\n            }\n        },\n        \"category\": [\n            \"Uncategorized\"\n        ],\n        \"page_template\": \"\"\n    }\n}\n<\/code><\/pre>\n<h4>Term and taxonomy page `dataLayer` structure<\/h4>\n<pre><code>{\n    \"event\": \"view_archive_category\", \/\/ this event name changed for every taxonomy\n    \"page\": {\n        \"type\": \"archive\",\n        \"title\": \"Uncategorized archives - Example\",\n        \"url\": \"https:\/\/example.com\/blog\/category\/uncategorized\",\n        \"path\": \"blog\/category\/uncategorized\",\n        \"locale\": \"en_US\",\n        \"archive_type\": \"taxonomy\",\n        \"taxonomy\": \"category\",\n        \"post_type\": \"category\",\n        \"date\": {\n            \"year\": null,\n            \"month\": null,\n            \"day\": null\n        }\n    }\n}\n<\/code><\/pre>\n<h4>Pagination `dataLayer` structure<\/h4>\n<p>The <code>pagination<\/code> object structure is automatically added to all pages that have pagination.<\/p>\n<p>Easy access to your pagination data, detect if users are using your pagination as much as you want.<\/p>\n<pre><code>{\n    pagination: {\n        \"posts_per_page\": 10,\n        \"post_count\": 1,\n        \"paged\": true,\n        \"page_number\": 2,\n        \"max_num_pages\": 5\n    }\n}\n<\/code><\/pre>\n<h4>Authenticated user `dataLayer` structure<\/h4>\n<p>The <code>user<\/code> object is automatically added to all page when user is logged in.<\/p>\n<p>User hashed data with SHA256 is very useful for GDPR consent with Google Ads services and user provided data.<\/p>\n<pre><code>{\n    user: {\n        \"id\": 1,\n        \"user_login\": \"openmost\",\n        \"user_nicename\": \"Openmost\",\n        \"user_email\": \"no-reply@openmost.io\",\n        \"user_registered\": \"2024-01-01 12:00:00\",\n        \"display_name\": \"openmost\",\n        \"roles\": [\n            \"administrator\"\n        ],\n        \"sha256_id\": \"6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b\",\n        \"sha256_user_login\": \"b2754b994c2fb636d1943ac0170f4ea192a891fb0f09cfdd100a9ffa983f053d\",\n        \"sha256_user_email\": \"679d031c25e557ee84ca86ecaf333ccd8d3d1a3900ee728da83d79a819daf535\"\n    }\n}\n<\/code><\/pre>\n<h4>Plugin : Contact Form 7 `dataLayer` structure<\/h4>\n<p>This plugin automatically detects the use of WP Contact Form 7.<br \/>\nNo configuration needed.<\/p>\n<p>Form submitted<\/p>\n<pre><code>{\n    \"event\": \"wpcf7_submit\",\n    \"wpcf7_form_id\": 145,\n    \"wpcf7_form_detail\": {} \/\/ See wpcf7_form_details below\n}\n<\/code><\/pre>\n<p>Form with invalid fields<\/p>\n<pre><code>{\n    \"event\": \"wpcf7_invalid\",\n    \"wpcf7_form_id\": 145,\n    \"wpcf7_form_detail\": {} \/\/ See wpcf7_form_details below\n}\n<\/code><\/pre>\n<p>Form spamming detected<\/p>\n<pre><code>{\n    \"event\": \"wpcf7_spam\",\n    \"wpcf7_form_id\": 145,\n    \"wpcf7_form_detail\": {} \/\/ See wpcf7_form_details below\n}\n<\/code><\/pre>\n<p>Email sent successfully<\/p>\n<pre><code>{\n    \"event\": \"wpcf7_mail_sent\",\n    \"wpcf7_form_id\": 145,\n    \"wpcf7_form_detail\": {} \/\/ See wpcf7_form_details below\n}\n<\/code><\/pre>\n<p>Failed to send mail<\/p>\n<pre><code>{\n    \"event\": \"wpcf7_mail_failed\",\n    \"wpcf7_form_id\": 145,\n    \"wpcf7_form_detail\": {} \/\/ See wpcf7_form_details below\n}\n<\/code><\/pre>\n<p>As each event handles <code>wpcf7_form_details<\/code>, here is an example of the object values when the form is submitted with invalid fields.<\/p>\n<pre><code>\"wpcf7_form_detail\": {\n        \"contactFormId\": 145,\n        \"pluginVersion\": \"6.0.3\",\n        \"contactFormLocale\": \"en_US\",\n        \"unitTag\": \"wpcf7-xxxxxx\",\n        \"containerPostId\": 0,\n        \"status\": \"validation_failed\",\n        \"inputs\": [\n            {\n                \"name\": \"your-message\",\n                \"value\": \"\"\n            },\n            {\n                \"name\": \"your-name\",\n                \"value\": \"\"\n            },\n            \/\/ All other inputs\n        ],\n        \"formData\": {},\n        \"apiResponse\": {\n            \"contact_form_id\": 145,\n            \"status\": \"validation_failed\",\n            \"message\": \"One or more fields contain an error. Please check and try again.\",\n            \"invalid_fields\": [\n                {\n                    \"field\": \"your-name\",\n                    \"message\": \"Please complete this field..\",\n                    \"idref\": \"last_name\",\n                    \"error_id\": \"wpcf7-f145-o1-ve-your-name\"\n                },\n                {\n                    \"field\": \"your-first-name\",\n                    \"message\": \"Please complete this field.\",\n                    \"idref\": \"first_name\",\n                    \"error_id\": \"wpcf7-f145-o1-ve-your-first-name\"\n                },\n                \/\/ All other invalid fields\n            ],\n            \"posted_data_hash\": \"\",\n            \"into\": \"#wpcf7-f145-o1\"\n        }\n    }\n<\/code><\/pre>\n<h4>Plugin : WP Forms `dataLayer` structure<\/h4>\n<pre><code>{\n    event: 'wp_forms_submit',\n    wp_forms_form_detail: {} \/\/ the HTML tag found in DOM\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Add contextual information to dataLayer for GTM and MTM<\/p>\n","protected":false},"author":65,"featured_media":416644,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"DataLayer for GTM and Matomo - \u8587\u6653\u6735\u63d2\u4ef6\u76ee\u5f55","description":"Add contextual information to dataLayer for GTM and MTM"},"footnotes":""},"categories":[1],"tags":[457,16590,1499,1894,24336],"class_list":["post-416642","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-analytics","tag-datalayer","tag-google-tag-manager","tag-gtm","tag-matomo"],"_links":{"self":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/416642","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/comments?post=416642"}],"version-history":[{"count":0,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/416642\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media\/416644"}],"wp:attachment":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media?parent=416642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/categories?post=416642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/tags?post=416642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}