{"id":19146412,"url":"https://github.com/netzstrategen/wordpress-shop-analytics","last_synced_at":"2026-02-09T17:32:20.965Z","repository":{"id":35176959,"uuid":"95665815","full_name":"netzstrategen/wordpress-shop-analytics","owner":"netzstrategen","description":"WordPress integration plugin for Google Analytics.","archived":false,"fork":false,"pushed_at":"2025-01-21T14:46:15.000Z","size":171,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-03-28T05:03:41.471Z","etag":null,"topics":["analytics","google-analytics","google-analytics-api","javascript","php","wordpress","wordpress-plugin"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/netzstrategen.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":"2017-06-28T12:17:15.000Z","updated_at":"2025-01-21T14:46:18.000Z","dependencies_parsed_at":"2024-11-09T07:44:11.974Z","dependency_job_id":"231ed35e-da64-4912-b97d-d6ff1c0e7722","html_url":"https://github.com/netzstrategen/wordpress-shop-analytics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netzstrategen%2Fwordpress-shop-analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netzstrategen%2Fwordpress-shop-analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netzstrategen%2Fwordpress-shop-analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netzstrategen%2Fwordpress-shop-analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/netzstrategen","download_url":"https://codeload.github.com/netzstrategen/wordpress-shop-analytics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248914127,"owners_count":21182360,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["analytics","google-analytics","google-analytics-api","javascript","php","wordpress","wordpress-plugin"],"created_at":"2024-11-09T07:44:03.301Z","updated_at":"2026-02-09T17:32:15.930Z","avatar_url":"https://github.com/netzstrategen.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Wordpress Shop Analytics\nThis plugin tracks the activity of customers in WooCommerce based ecommerce sites and sends the collected data to Google Data Layer.\n\nThe plugin acts in two general areas:\n- __Static Tracking:__ Tracking of information about the page currently displayed.\n- __Dynamic Tracking:__ Tracking of the events triggered by the customers as they interact with the site.\n\nIn order to implement these functionalities, the plugin relies on Google Tag manager script. The plugin takes care of adding the GTM script in the page, once the required GTM ID is added to its backend configuration settings and the script injection enabled.\n\nThe (very) initial concept and requirements description of `shop-analytics` plugin can be found [in this document](https://docs.google.com/document/d/1Wpe4YoVDrdgiXtzfuSmIh36rEpaJ0gM87LMKST8BacQ/edit#heading=h.qu6ahb5mfd10). However, the plugin has grown and considerably evolved in complexity and functionality since then.\n## Shop Analytics configuration settings\n\nThe plugin has a dedicated configuration settings page (`wp-admin/admin.php?page=shop-analytics`). Upon activation, the plugin adds a `Shop Analytics` entry to the WordPress admin menu.\n\nThe available configuration settings are:\n- __Google Tag Manager Container ID:__ account ID to be used by Tag Manager script.\n- __Google Tag Manager script embed:__ if checked, enabled the injection of the GTM script.\n- __TagCommander enabled:__ Enables TagCommander variable optout.\n- __Track User ID:__ if checked, user ID is tracked.\n- __Use anonymized E-Mail address as User ID:__ if checked, anonymized E-Mail address is applied as user ID.\n- __Track User Role:__ if checked, user role is tracked.\n- __Disable User Tracking:__ user roles that should not be tracked.\n- __Enable E-Commerce tracking:__ if checked, e-commerce related activity is tracked.\n- __Market code (fallback value):__ market default code.\n- __Enable GA dataLayer console logging:__ if checked, data object pushed to Google Data Layer is printed in the browser console. Useful for debugging purposes.\n- __Attribute used as product brand:__ if a product attribute is used to manage product brands (instead of the WooCommerce native brand field), it can be selected here. This is necessary to correctly track products brand.\n- __Attribute used as product category:__ if a product attribute is used to manage product categories (instead of regular categories), it can be selected here. This is necessary to correctly track products categories.\n## Static Tracking\n\nSeveral relevant details about the site page displayed are sent to GTM. This is achieved by injecting data attribute fields in the `\u003chtml\u003e` tag. [See code](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/src/Plugin.php#L101).\n\nThe data fields can vary depending on the type of page visited. Some data fields are used in all cases.\n\n- __Common data fields:__\n  - `language`: Site language.\n  - `user-id`: User ID (if logged in).\n  - `user-type`: User role.\n  - `user-track`: tracking status for current user (`1` means tracked, `0` not tracked).\n\n- __Not commerce related__\n  - `page-type`: Page type. Possible values are:\n    - Home\n    - Page\n    - Post\n    - Tag\n    - Category\n    - Search\n    - Other\n- __Commerce related, if tracking enabled in backend settings:__\n  - `page-type`: Page type. Possible values are:\n    - Product single\n      - Additionally: Product details and attributes.\n        - `product-{detail name}`: product details.\n        - `product-{attribute name}`: product attributes.\n    - Product category, and\n      - `product-category`: Category path\n      - `product-count`: Products count in current taxonomy.\n    - Product tag, and\n      - `product-tag`: Tag name,\n      - `product-count`: Products count in current taxonomy.\n    - Cart\n    - Checkout\n  - `market`: Market designation.\n  - `currency`: Currency in use.\n\nE.g\nHomepage\n```\n\u003chtml class=\"no-js\" lang=\"de\" data-language=\"de\" data-user-id=\"cee037efd9a618bc4d1e8773eb18d2278370b798\" data-user-type=\"administrator\" data-user-track=\"0\" data-page-type=\"Home\" data-market=\"GLOBAL\" data-currency=\"EUR\"\u003e\n```\nContent page\n```\n\u003chtml class=\"no-js\" lang=\"de\" data-language=\"de\" data-user-id=\"cee037efd9a618bc4d1e8773eb18d2278370b798\" data-user-type=\"administrator\" data-user-track=\"0\" data-page-type=\"Page\" data-market=\"GLOBAL\" data-currency=\"EUR\"\n```\nSearch results page\n```\n\u003chtml class=\"no-js\" lang=\"de\" data-language=\"de\" data-user-id=\"cee037efd9a618bc4d1e8773eb18d2278370b798\" data-user-type=\"administrator\" data-user-track=\"0\" data-page-type=\"Search\" data-market=\"GLOBAL\" data-currency=\"CHF\"\u003e\n```\n\nProduct category listing\n```\n\u003chtml class=\"no-js\" lang=\"de\" data-language=\"de\" data-user-id=\"cee037efd9a618bc4d1e8773eb18d2278370b798\" data-user-type=\"administrator\" data-user-track=\"0\" data-page-type=\"Product | Category\" data-market=\"GLOBAL\" data-currency=\"EUR\" data-product-category=\"Loungemöbel \u003e Fix \u0026amp; Fertig \u003e Loungesets\" data-product-count=\"173\"\u003e\n```\nSingle product\n```\n\u003chtml class=\"no-js\" lang=\"de\" data-language=\"de\" data-user-id=\"cee037efd9a618bc4d1e8773eb18d2278370b798\" data-user-type=\"administrator\" data-user-track=\"0\" data-page-type=\"Product | Variable\" data-market=\"GLOBAL\" data-currency=\"EUR\" data-product-id=\"237112\" data-product-sku=\"213520-M\" data-product-name=\"4Seasons Outdoor Accor Diningsessel\" data-product-type=\"variable\" data-product-price=\"294.00\" data-product-category=\"Gartenmöbel \u003e Basics \u003e Gartenstühle\" data-product-brand=\"4Seasons Outdoor\" data-product-availability=\"In stock\" data-product-stock=\"2\" data-product-currency=\"EUR\" data-product-delivery-time=\"ca. 8-10 Werktage (Lagerartikel)\" data-product-ausfuehrung-gestell=\"Edelstahl anthrazit\" data-product-ausfuehrung-sitzflaeche=\"Rope anthrazit | Rope mid grey\" data-product-material-kissen-bzw-auflage=\"100% Polypropylen (Olefin)\" data-product-farbe-kissen-bzw-auflage=\"grau\" data-product-pflegehinweis-kissen=\"abziehbar und waschbar\" data-product-wetterfestigkeit-kissen=\"gut - verträgt längeren Schauer\" data-product-breite=\"64 cm\" data-product-tiefe=\"62 cm\" data-product-hoehe=\"83 cm\" data-product-belastbarkeit=\"120 kg\" data-product-gewicht-ohne-verpackung=\"7 kg\" data-product-serie=\"4Seasons Outdoor Accor\" data-product-lieferzustand=\"montiert\"\n```\n## Dynamic tracking\n\nThe activity of the user in the site triggers diverse events that are also tracked by `shop-analytics` and sent to Google Data Layer. The user interactions the plugin watches are related to:\n- Navigation across the shop\n- Checkout steps and details\n\nIn order to collect the data to be sent to Google Data Layer, `shop-analytics` builds adds data attribute fields into hidden `\u003cdiv\u003e` and `\u003cspan\u003e` elements. This is done during the building and rendering of the page, relying on diverse WooCommerce hooks ([see code](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/src/Plugin.php#L50)). E.g.\n\nOn single product view ([see code](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/src/WooCommerce.php#L379))\n```html\n\u003cdiv class=\"shop-analytics-single-product-details\" style=\"display:none;height:0;\" data-id=\"237112\" data-sku=\"213520-M\" data-name=\"4Seasons Outdoor Accor Diningsessel\" data-type=\"variable\" data-price=\"294.00\" data-category=\"Gartenmöbel/Basics/Gartenstühle\" data-brand=\"4Seasons Outdoor\" data-availability=\"In stock\" data-stock=\"2\" data-currency=\"EUR\" data-delivery_time=\"ca. 8-10 Werktage (Lagerartikel)\"\u003e\u003c/div\u003e\n```\nIn cart page ([see code](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/src/WooCommerce.php#L338))\n```html\n\u003cspan class=\"shop-analytics-product-info\" data-id=\"237112\" data-sku=\"213520-M\" data-name=\"4Seasons Outdoor Accor Diningsessel\" data-type=\"variable\" data-price=\"294.00\" data-category=\"Gartenmöbel/Basics/Gartenstühle\" data-brand=\"4Seasons Outdoor\" data-availability=\"In stock\" data-stock=\"2\" data-currency=\"EUR\" data-delivery_time=\"ca. 8-10 Werktage (Lagerartikel)\" data-item_key=\"8587e5976f070d5eee05ff4d18262f38\" data-variant=\"Ausführung Sitzfläche: Rope anthrazit\" data-quantity=\"1\"\u003e\u003c/span\u003e\n```\nIn order confirmation page ([see code](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/src/WooCommerce.php#L423))\n```html\n\u003cdiv class=\"shop-analytics-order-details\" style=\"display:none;height:0;\" data-id=\"6023852\" data-currency=\"EUR\" data-revenue=\"578\" data-tax=\"79.72\" data-shipping=\"0\" data-shipping_tax=\"0\" data-payment-method=\"50% Vorkasse per Überweisung\" data-coupon=\"weil wir nett sind :-)\" data-order_count=\"2\"\u003e\n  \u003cdiv class=\"shop-analytics-product-details\" style=\"display:none;height:0;\" data-id=\"280274\" data-sku=\"213520\" data-name=\"4Seasons Outdoor Accor Diningsessel - Rope anthrazit\" data-type=\"variation\" data-price=\"294.00\" data-availability=\"Out of stock\" data-stock=\"0\" data-gtin=\"8720087001241\" data-currency=\"EUR\" data-delivery_time=\"ca. 8-10 Werktage (Lagerartikel)\" data-quantity=\"2\"\u003e\u003c/div\u003e\n\u003c/div\u003e\n```\n\nWhen the hidden element is ready, all the required data attribute fields added, a set of scripts take care of retrieve the information, organize it in a DataLayer object, and push it into Google DataLayer.\n\nThe JSON object pushed to Google Data Layer has a predefined basic format, which varies depending on the event to be tracked.\n\nE.g.\nProducts impressions (products listing page, partial data)\n```json\n{\n  \"event\": \"view_item_list\",\n  \"ecommerce\": {\n    \"currency\": \"EUR\",\n    \"items\": [\n      {\n        \"item_name\": \"4Seasons Outdoor Accor Diningsessel\",\n        \"item_id\": \"213520-M\",\n        \"price\": \"294.00\",\n        \"item_category\": \"Gartenmöbel/Basics/Gartenstühle\",\n        \"item_brand\": \"4Seasons Outdoor\",\n        \"position\": 1,\n        \"item_list_name\": \"Product Category\"\n      },\n      {\n        \"item_name\": \"4Seasons Outdoor Athena Diningsessel\",\n        \"item_id\": \"91013\",\n        \"price\": \"249.00\",\n        \"item_category\": \"Gartenmöbel/Basics/Gartenstühle\",\n        \"item_brand\": \"4Seasons Outdoor\",\n        \"position\": 2,\n        \"item_list_name\": \"Product Category\"\n      },\n      {\n        \"item_name\": \"Cane-line Diamond GartenstuhlTextilgewebe\",\n        \"item_id\": \"8401TXW-M\",\n        \"price\": \"484.00\",\n        \"item_category\": \"Gartenmöbel/Basics/Gartenstühle\",\n        \"item_brand\": \"Cane-line\",\n        \"position\": 3,\n        \"item_list_name\": \"Product Category\"\n      },\n      {\n\n      }\n    ]\n  },\n  \"gtm.uniqueEventId\": 12\n}\n```\nSingle product view\n```json\n{\n  \"event\": \"view_item\",\n  \"ecommerce\": {\n    \"items\": [\n      {\n        \"item_name\": \"4Seasons Outdoor Accor Diningsessel\",\n        \"item_id\": \"213520-M\",\n        \"price\": \"294.00\",\n        \"item_category\": \"Gartenmöbel/Basics/Gartenstühle\",\n        \"item_brand\": \"4Seasons Outdoor\",\n        \"item_list_name\": \"Product detail\"\n      }\n    ]\n  },\n  \"gtm.uniqueEventId\": 12\n}\n```\n\nAdd product(s) to cart\n```json\n{\n  \"event\": \"add_to_cart\",\n  \"ecommerce\": {\n    \"currency\": \"EUR\",\n    \"items\": [\n      {\n        \"item_name\": \"4Seasons Outdoor Accor Diningsessel\",\n        \"item_id\": \"280274\",\n        \"price\": \"294.00\",\n        \"item_category\": \"Gartenmöbel/Basics/Gartenstühle\",\n        \"item_brand\": \"4Seasons Outdoor\",\n        \"item_variant\": \"Rope anthrazit\",\n        \"quantity\": 1\n      }\n    ]\n  },\n  \"gtm.uniqueEventId\": 48\n}\n```\nThe events tracked are:\n- Navigation\n  - [Click on navigation element](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/common.js#L433)\n- User\n  - [New user registration](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/common.js#L401)\n  - [New user registration during checkout](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/common.js#L414)\n  - [User login](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/common.js#L388)\n- Products listings\n  - [Product impressions](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/common.js#L226)\n  - [Click on product](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/common.js#L302)\n- Single product\n  - [View single product page](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/product.js#L16)\n  - [Add product to cart](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/common.js#L341)\n  - [Update product quantity](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/product.js#L48)\n  - [Product variation selection](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/product.js#L57)\n  - [Show product gallery](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/product.js#L77)\n- Cart\n  - [Update cart totals](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/cart-checkout.js#L36)\n  - [Update product quantity in cart](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/cart-checkout.js#L36)\n  - [Remove product from cart](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/common.js#L459)\n  - [Empty cart](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/common.js#L424)\n- Checkout\n  - [Update shipping method](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/cart-checkout.js#L36)\n  - [Update payment method](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/cart-checkout.js#L36)\n  - [Update billing address](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/cart-checkout.js#L36)\n  - [Update shipping address](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/cart-checkout.js#L108)\n  - [Order placed](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/cart-checkout.js#L72)\n  - WooCommerce checkout enpoints ([See code](https://github.com/netzstrategen/wordpress-shop-analytics/blob/3f326907a7bb49db30b67cc9bd0c3538850d93b5/src/Plugin.php#L281)), represented with an integer value (default values can be [modified with a filter](#backend)).\n    - `view-order`\n    - `edit-account`\n    - `edit-address`\n    - `lost-password`\n    - `customer-logout`\n    - `add-payment-method`\n    - `order-pay`\n    - `order-received`\n\n## Code customization\n\n### Backend\nCode customization is possible using the provided filters:\n- [shop_analytics_product_meta_key_gtin](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/src/WooCommerce.php#L85): allows to modify the name (value of `meta_key`) of the meta field used to store the products GTIN.\n- [shop_analytics_checkout_steps](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/src/Plugin.php#L276): allows to modify the integer used to represent each WooCommerce checkout step.\n- [shop_analytics_wc_endpoints](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/src/Plugin.php#L281): allows to modify the integer used to represent each WooCommerce endpoint.\n- [shop_analytics_checkout_step__view_cart](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/src/Plugin.php#L301): allows to modify the integer used to represent WooCommerce `view_cart` checkout step.\n- [shop_analytics_checkout_step__checkout_pay](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/src/Plugin.php#L305): allows to modify the integer used to represent WooCommerce `pay` checkout step.\n- [shop_analytics_checkout_step__checkout_page](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/src/Plugin.php#L308): allows to modify the integer used to represent WooCommerce `checkout_page` checkout step.\n- [shop_analytics_checkout_step_current](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/src/Plugin.php#L308): allows to modify the integer passed to the frontend to represent WooCommerce current checkout step.\n\n### Frontend (JS)\nIt is possible to override many default values modifying the entries of the properties of the object `shopAnalytics`, which is [added to the browser document object as a property](https://github.com/netzstrategen/wordpress-shop-analytics/blob/5b410895b76599adf24ada7feac5733c71c42c95/assets/scripts/datalayer/common.js#L129-L180). This allows to customize the selectors used to trigger some dynamic tracking events, if necessary.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetzstrategen%2Fwordpress-shop-analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetzstrategen%2Fwordpress-shop-analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetzstrategen%2Fwordpress-shop-analytics/lists"}