Giter Site home page Giter Site logo

fnogatz / magento2-matomo Goto Github PK

View Code? Open in Web Editor NEW
50.0 15.0 34.0 242 KB

Matomo Analytics Module for Magento 2

License: GNU Affero General Public License v3.0

PHP 90.48% HTML 2.18% JavaScript 6.15% Shell 1.19%
piwik magento magento2 magento2-module piwik-tracking agpl matomo composer

magento2-matomo's Introduction

Matomo Integration for Magento 2

Chessio_Matomo is a Matomo web analytics module for the Magento 2 eCommerce platform. Matomo is an extensible free/libre analytics tool that can be self-hosted, giving you complete data ownership. Chessio_Matomo lets you integrate Matomo with your Magento 2 store front.

This module is the successor of Henhed_Piwik and thus continues with its semantic versioning, beginning with version v2.1.0 . If you're using a Magento version prior to 2.2, you'll need to stick to the 1.x releases of the original Henhed_Piwik. For manual installation, check out the Releases archive. For installation using Composer, you can use the tilde or caret version constraint operators (e.g. ~1.3 or ^1.3.1).

Installation

To install Chessio_Matomo, download and extract the main zip archive and move the extracted folder to app/code/Chessio/Matomo in your Magento 2 installation directory.

unzip magento2-matomo-main.zip
mkdir app/code/Chessio
mv magento2-matomo-main app/code/Chessio/Matomo

Alternatively, you can clone the Chessio_Matomo Git repository into app/code/Chessio_Matomo.

git clone https://github.com/fnogatz/magento2-matomo.git app/code/Chessio/Matomo

Or, if you prefer, install it using Composer.

composer require chessio/module-matomo

Finally, enable the module with the Magento CLI tool.

php bin/magento module:enable Chessio_Matomo --clear-static-content

Configuration

Once installed, configuration options can be found in the Magento 2 administration panel under Stores/Configuration/Sales/Matomo API. To start tracking, set Enable Tracking to Yes, enter the Hostname of your Matomo installation and click Save Config. If you have multiple websites in the same Matomo installation, make sure the Site ID configured in Magento is correct.

Customization

If you need to send some custom information to your Matomo server, Chessio_Matomo lets you do so using event observers.

To set custom data on each page, use the matomo_track_page_view_before event. A tracker instance will be passed along with the event object to your observer's execute method.

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $tracker = $observer->getEvent()->getTracker();
    /** @var \Chessio\Matomo\Model\Tracker $tracker */
    $tracker->setDocumentTitle('My Custom Title');
}

If you only want to add data under some specific circumstance, find a suitable event and request the tracker singleton in your observer's constructor. Store the tracker in a class member variable for later use in the execute method.

public function __construct(\Chessio\Matomo\Model\Tracker $matomoTracker)
{
    $this->_matomoTracker = $matomoTracker;
}

Beware of tracking user specific information on the server side as it will most likely cause caching problems. Instead, use Javascript to retrieve the user data from a cookie, localStorage or some Ajax request and then push the data to Matomo using either the Chessio_Matomo JS component...

require(['Chessio_Matomo/js/tracker'], function (trackerComponent) {
    trackerComponent.getTracker().done(function (tracker) {
        // Do something with tracker
    });
});

... or the vanilla Matomo approach:

var _paq = _paq || [];
_paq.push(['setDocumentTitle', 'My Custom Title']);

See the Matomo Developer Docs or the \Chessio\Matomo\Model\Tracker source code for a list of all methods available in the Tracking API.

magento2-matomo's People

Contributors

antonio-lolic-typeqast avatar fnogatz avatar henkelund avatar igerchak avatar igortregub avatar ihor-sviziev avatar iw0der avatar zamu87 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

magento2-matomo's Issues

Adblock

Adblock and similar extensions block whatever has "piwik" either in reference URL or in context present.

Would you consider refactoring your extension in order to hide the Piwik mentions in generated JS and HTML code in order to avoid such Browser extensions blocking the tracking info?

Also, would be nice to have the ability to select in admin a custom tracking .JS file, but not to have piwik.php and piwik.js hardcoded!!!

Thanks!

Customization Tracking

I had one event payment_form_success (custom). That event is executed on successful payment of order. I put logger on it and its working. There I want to tracking success payment event track. I used observer for this event. There I put this code.
$this->_piwikTracker->trackEvent('payment', 'Payment for Order Id', '576');
$this->_piwikTracker object is load in construct.
Its still not tracking. I didn't find why its not tracking.

PHP 7.4 support open pull request needs merged.

I tested this on my install by manually editing composer.json and making the edit, it works perfectly.

Merging the pull request will allow people to install using composer, which is what I originally tried before cloning the repository and manually editing the composer file.

open pull request:

#45

Item Category not defined with Magento 2 plugin

Hi everyone,
I installed successfully the plugin and i have access to my ecommerce data in magento EXEPT for item cateogry
screen-categories-produits-matomo
When i look to my data layer, everything seem ok :

'event': 'product_view', 'ecommerce': { 'product': { 'sku': sku, 'name': name, 'categories':categoryName, 'price': price, 'cagnotte': cagnotte, 'co2e': co2e, 'brand': brand, 'vendor': vendor

I want to say that i have access to item ID in my matomo reports, but the category still undefined.

Anyone having this issues ?

SiteID value checks

I am using new Piwik module ProtectTrackID that generates alpha-numeric hash for default numeric site ID.

When entering the Alpha-numeric hash like 40c616cb45254119 the module throws an error on PiwikAPI settings page. Would you mind please include english characters, buth lower and upper case, into ID check rule, and publish it to custom-variables branch?

Content Security Policy

Under Magento 2.4.3-p1 the files form matomo are blocked (matomo.js: "script-src" and matomo.php: "connect-src" ).
Matomo is installed under a subdomain: https://matomo.domain.tld.

How can I fix this error?

thx opaque

The method setTrackerUrl is registered more than once in "_paq" variable

Hi,

I'm experiencing the following error in Chrome / Opera / Vivaldi but not in Firefox :
The method setTrackerUrl is registered more than once in "_paq" variable

In Firefox <head> contains only one occurrence of :

<head>
<script type="text/javascript" async="" defer="" src="https://stats.mydomain.com/kiwi.js"></script>
...
</head>

when in others browser I have it twice :

<head>
<script type="text/javascript" async="" defer="" src="https://stats.mydomain.com/kiwi.js"></script>
...
<script type="text/javascript" async="async" defer="defer" src="https://stats.mydomain.com/kiwi.js"></script>
</head>

Here is a curl output (no js applied) of a page :

...
<script type="text/x-magento-init">
{"*":{"Henhed_Piwik\/js\/tracker":{"scriptUrl":"https:\/\/stats.mydomain.com\/kiwi.js","trackerUrl":"https:\/\/stats.mydomain.com\/kiwi.php","siteId":1,"actions":[["enableLinkTracking",true],["setLinkTrackingTimer",500],["trackPageView"]]$
<script type="text/javascript">
(function (w, d) {
    w._paq = w._paq || [];
    w._paq.push(['setTrackerUrl', 'https://stats.mydomain.com/kiwi.php']);
    w._paq.push(['setSiteId', 1]);
    w._paq.push(['setRequestMethod', 'POST']);
    var g = d.createElement('script'),
        s = d.getElementsByTagName('script')[0];
    g.type = 'text/javascript';
    g.async = true;
    g.defer = true;
    g.src = 'https://stats.mydomain.co/kiwi.js';
    s.parentNode.insertBefore(g, s);
})(window, document);
</script>
<noscript>
    <p>
        <img src="https://stats.mydomain.com/kiwi.php?idsite=1&rec=1&url=https%3A%2F%2Fwww.mydomain.com%2F"
             style="border: 0;"
             alt="" />
    </p>
</noscript>
...

I'm using the js/php renaming, but the same error occurs with standard piwik too.

Are you able to reproduce the issue ?

M2.1.3 no html code generated

After M2 upgrade to 2.1.3 no HTML code is generated.
I am using custom-variables branch. Please look into the issue.

Support Matomo Tag Manager

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.

FYI: Piwik is now Matomo.

Stripping trailing slash from PHP Script Path and Javascript Path causes unnecessary webserver redirects when using "js/"

Hi,

To get around the adblock issue, piwik (or should I now say Matamo) recommend that you use the script paths "js/" instead of "piwik.js" and "piwik.php" as "js/" is automatically handled by Matamo, and not blocked by Adblock.

However, when the henhed module makes the call, the trailing slash is removed and the url "js" is called. This causes the webserver to respond with a redirect to "js/". Whilst it all still works, it means two webserver calls instead of one for every page view.

What is the reason for removing the trailing slash?

Thanks

Graham

Excluding parameters

Please can someone advise how we are meant to exclude URL query parameters as I can't see anything for this in the configuration...?

For example, if we want to exclude the parameter fbclid, then this line is added in the tracking code:

_paq.push(["setExcludedQueryParams", ["fbclid"]]);

Thanks for any pointers.

PHP 7.1

Hi there, any chance to make it work with PHP 7.1? Many thanks, Bernard

Wrong Counter with this plugin.

Hello,
after we migrate to magento2 and used this plugin, we have wrong visitors count.

After Migration
image

Google Analytics said a other thinks.

image

Feature request: show customer currency

My store use 1 base currency and multiple user currencies. I noticed Matomo report just the base currency even if the customer is adding a product which is shown in another currency.

It would be nice to show on Matomo report both: the base currency and the user local currency (if it's different).

No data has been recorded yet

No data has been recorded yet, as i am using magento extension for piwik for JavaScript tracking code but no result is coming for visit log and and order. I have checked date and all but no visit log is coming.

Matomo for M2 extension is not compatible with M2.4.4 released April 2022

More specifically it appears to use php 7 syntax that is deprecated in the php 8 version required by Magento 2.4.4 release.

$ php bin/magento --version
Magento CLI 2.4.4
$ php -v
PHP 8.1.4 (cli) (built: Apr 12 2022 11:12:25) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.4, Copyright (c) Zend Technologies
$ composer require chessio/module-matomo

[InvalidArgumentException]
Package chessio/module-matomo has requirements incompatible with your PHP version, PHP extensions and Composer version:
- chessio/module-matomo v2.1.3 requires php ~7.0.0|~7.1.0|~7.2.0|~7.3.0|~7.4.0 which does not match your installed version 8.1.4.

No transfer of shopping cart contents

Hello,

Magento 2.2.2
Henhed_Piwik
Matomo 3.3.0

Tracking works until the shopping cart, but the checkout does not transfer the data and the shopping cart is empty.
It's not always like that, sometimes it works.
Does anyone know the problem and has a solution?

Best regards
Klaus

Installed and enabled the plugin but it can't enable anything in magento 2 admin page

Hi. Thank you for making this plugin.
I have followed the installation guide and installed henhed-piwik 1.3.1 for magento2.2.
I can see the Piwik API session under admin dashboard but there aren't anything to select as shown in the picture.

magento2

Is there anything could make this happen?

I am currently placing the plugin in magento2/app/code/henhed/magento2-henhed-piwik

Thanks in advance!

Cannot declare class Henhed\Piwik\Helper\Tracker

Hi,
I think this is a trivial problem but can not find a way out of this ...

bash-4.2$ bin/magento setup:di:compile Compilation was started. Repositories code generation... 1/7 [====>-----------------------] 14% 1 sec 74.8 MiBPHP Fatal error: Cannot declare class Henhed\Piwik\Helper\Tracker because the name is already in use in /www/app/code/Henhed/Piwik/Helper/Tracker.php on line 32 b

I deleted a lot of things (static content, cache, etc.) but keep getting this error message :-(

Thx,
A.

Add support for php 7.3

Magento supports and recommends php 7.3 from 2.3.4 on,
pls adjust composer.json as code seems to work.

Feature request: support cdnjs

Hello, thank you for a great tool! I would love to be able to download the piwik.js from CDNJS instead of my local server. I tried to use the CDN hostname on the Magento Backend for that:

PHP Script Path: piwik.php
Javascript Path: piwik.min.js
CDN Hostname: cdnjs.cloudflare.com/ajax/libs/piwik/3.14.0/

Unfortunately this does not seem to work because the visits are not counted. Can this be because of cross-site scripting? What is the best way to include the full Script tag:

<script src="https://cdnjs.cloudflare.com/ajax/libs/piwik/3.14.0/piwik.min.js" integrity="sha512-Glp1LVjhpv3ADmJuxE0SdJvV++Bzo39bwy820nGjA82GzH/UNvnf02G9IeZGMxITlZy6w9Ixv868uqsaH8Xkhw==" crossorigin="anonymous"></script>

Would that avoid the issues with cross-site scripting? The library is on cdnjs:
https://cdnjs.com/libraries/piwik

Add dependencies on magento core modules

I don't see in composer.json require section any magento modules are required for correct work if this module.

There is dependencies to:

If any of these modules will have backward incompatible version that is not tested with this module - it might brake this module. In order to fix it we need to add dependencies to supported module versions.

Also it's not clear, do this module supports Magento 2.2.2?

The method setTrackerUrl is registered more than once in "_paq" variable

I've faced the same issue as It was described in #15

Preconditions

  1. Magento 2.2.3
  2. henhed/module-piwik 2.0.0
  3. Google Chrome

Steps to reproduce

  1. open dev console
  2. add some product to the Shopping Cart
  3. go to the checkout page
  4. see errors on the dev console

Expected result

  1. there mustn't be any errors on the dev console

Actual result

  1. there are js errors:
    piwik-js-console-error

if this issue you cannot reproduce, refresh your checkout page few times

It's happening because on the checkout page code
https://github.com/henkelund/magento2-henhed-piwik/blob/master/view/frontend/templates/piwik.phtml#L36-L49
runs in paralel with code
https://github.com/henkelund/magento2-henhed-piwik/blob/master/view/frontend/web/js/tracker.js#L298-L303
as result tracker.js tries to inject piwik.js file second time.

My PR adds checking if such script already exists on this page: #27

Module not working with Magento 2.4.0

Just tried to install it using composer on Magento 2.4.0 and I received this error message:

[InvalidArgumentException]
Package henhed/module-piwik at version  has a PHP requirement incompatible with your PHP version (7.4.3)

Any chances to make this working on it?

Issue - Piwik is not initialized

Hello,

I installed the module Piwik for Magento 2 and configured. Looking to the browser console I'm gathering many issue regarding Piwik like:

_paq.push() was used but Piwik tracker was not initialized before the piwik.js file was loaded. Make sure to configure the tracker via paq.push before loading piwik.js. Alternatively, you can create a tracker via Piwik.addTracker() manually and then use paq.push but it may not fully work as tracker methods may not be executed in the correct order. Array[2]0: "setSiteId"1: 1length: 2__proto: Array[0]
push @ piwik.js:70
pushAction @ tracker.js:202
(anonymous) @ tracker.js:194
.each..forEach @ underscore.js:145
pushAction @ tracker.js:193
initialize @ tracker.js:239
(anonymous) @ main.js:30
execCb @ require.js:1650
check @ require.js:866
(anonymous) @ require.js:1113
(anonymous) @ require.js:132
(anonymous) @ require.js:1156
each @ require.js:57
emit @ require.js:1155
check @ require.js:917
(anonymous) @ require.js:1113
(anonymous) @ require.js:132
(anonymous) @ require.js:1156
each @ require.js:57
emit @ require.js:1155
check @ require.js:917
(anonymous) @ require.js:1113
(anonymous) @ require.js:132
(anonymous) @ require.js:1156
each @ require.js:57
emit @ require.js:1155
check @ require.js:917
(anonymous) @ require.js:1113
(anonymous) @ require.js:132
(anonymous) @ require.js:1156
each @ require.js:57
emit @ require.js:1155
check @ require.js:917
enable @ require.js:1143
init @ require.js:774
callGetModule @ require.js:1170
completeLoad @ require.js:1544
onScriptLoad @ require.js:1671

Can you help me?!

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.