Coder Social home page Coder Social logo

Comments (9)

henkelund avatar henkelund commented on May 24, 2024

I'll look into it when I get some time to spare

from magento2-matomo.

henkelund avatar henkelund commented on May 24, 2024

Iv'e made a branch called user-id that you're welcome to try out. If you're using composer you can require it with composer require henhed/module-piwik:dev-user-id. To start tracking the user ID you must first activate the Enable User ID Tracking setting in the Magento admin panel.

I think it works pretty well so far, except when signing out. The documentation states that:

If then visitor logs out then the visitor has no User ID set any more and a new visit will be created on the page view right after logging out.

This seems not to be the case. At least in my tests with Piwik 3.0.1, the subsequent page views after logging out are still attributed to the logged-in user, even though the user ID is no longer being sent. I'm not sure how big of an issue that is though, as the visit_standard_length Piwik setting will eventually create a new visit if the browsing is idle for long enough. It looks like there is an open bug report for this issue so maybe this is good enough for now?

Please let me know what you think and if this feature works as you expected.

Cheers,
H

from magento2-matomo.

souzavitor avatar souzavitor commented on May 24, 2024

I've seen the update you made and It's working fine, thanks.

But I think it is better to use the customer email instead of the customer id. Or maybe it could be configured.

from magento2-matomo.

henkelund avatar henkelund commented on May 24, 2024

If you want to use the customer email you can change preference for the user ID provider in another module's etc/di.xml:

<preference for="Henhed\Piwik\Model\UserId\ProviderInterface" type="Foo\Bar\UserId" />

And implement the interface like so:

<?php

namespace Foo\Bar;

class UserId implements \Henhed\Piwik\Model\UserId\ProviderInterface
{

    protected $_customerRepository;

    public function __construct(
        \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
    ) {
        $this->_customerRepository = $customerRepository;
    }

    public function getUserId($customerId)
    {
        try {
            return $this->_customerRepository->getById($customerId)->getEmail();
        } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
            return false;
        }
    }
}

Note: You might have to add Henhed_Piwik to your module's <sequence> and run setup:upgrade for the preference to take effect.

There are a few reasons why I chose to implemented it this way:

  • The customer entity ID is the most persistent identifier to use by default. A customer can change their email at any point which, I imagine, would confuse Piwik's visitor tracking.
  • A configuration setting for choosing either customer ID or email would be convenient, but it would also give admins the freedom to switch back and forth between the two, effectively changing the User ID of every single customer.
  • The entity ID is shorter than an email address which reduces the risk of hitting request size limits and requires less storage capacity in Piwik.
  • By providing an interface, the User ID is not limited to Magento's standard identifiers. Any custom logic or formatting can be applied. For instance, a merchant could implement it to use an ID from some external source, like a CRM, ERP or loyalty system.

I realize that it's a bit inconvenient but I think this approach provides more reliable data by default and is (with some effort) more flexible.

Do you agree with my point of view? If not, what makes email the better choice in you opinion?

from magento2-matomo.

souzavitor avatar souzavitor commented on May 24, 2024

I agree with you that makes sense to use the customer ID to track the user visits, but I think it's sometimes good to have the option to use another unique user information, such as email or username. I think that way it makes easier to identify the user in the Piwik reports.

In the Piwik documentation (http://piwik.org/docs/user-id/) we can see some good possibilities to use to track the user visit.

from magento2-matomo.

henkelund avatar henkelund commented on May 24, 2024

Ok, I've made an update to the same branch (user-id) that you're welcome to try out. The Enable User ID Tracking config option now lets you choose between entity ID and e-mail for user ID tracking.

It's still possible (but not required) to customize the user ID programmatically by adding more implementations of the user ID provider interface to Henhed\Piwik\UserId\Provider\Pool in your etc/di.xml file.

Please let me know if this update works well for you.

from magento2-matomo.

henkelund avatar henkelund commented on May 24, 2024

@souzavitor I'd like to include this feature in the next release. Have you had a chance to test my last update yet?

from magento2-matomo.

souzavitor avatar souzavitor commented on May 24, 2024

It works well for me, thank you very much!

from magento2-matomo.

henkelund avatar henkelund commented on May 24, 2024

@souzavitor Great!

I've removed the user-id branch. Please install version 1.3.0 instead (composer require henhed/module-piwik:v1.3.0)

from magento2-matomo.

Related Issues (20)

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.