Comments (9)
I'll look into it when I get some time to spare
from magento2-matomo.
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.
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.
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.
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.
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.
@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.
It works well for me, thank you very much!
from magento2-matomo.
@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)
- Travis builds fails due to missing environment variables HOT 1
- Installed and enabled the plugin but it can't enable anything in magento 2 admin page HOT 2
- No transfer of shopping cart contents HOT 1
- The method setTrackerUrl is registered more than once in "_paq" variable HOT 2
- Stripping trailing slash from PHP Script Path and Javascript Path causes unnecessary webserver redirects when using "js/" HOT 5
- Support Matomo Tag Manager HOT 6
- Magento 2.3. compatibility HOT 6
- Customization Tracking HOT 2
- Add support for php 7.3
- deleted
- Feature request: support cdnjs
- Module not working with Magento 2.4.0 HOT 5
- Feature request: show customer currency HOT 2
- PHP 7.4 support open pull request needs merged. HOT 1
- Fix Travis
- First search query is executed without page_size by including the "search.result" block HOT 1
- Migrate from Travis CI to GitHub Actions HOT 1
- Content Security Policy
- Matomo for M2 extension is not compatible with M2.4.4 released April 2022 HOT 5
- Excluding parameters
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magento2-matomo.