Reputation: 3437
I'm trying to adapt a solution from Google Analytics to Matomo. In Google Analytics I have:
My code is something like:
function track_download(data) {
var GA = window.ga || function() {
// ga is not defined, log function arguments
if (window.console) {
console.log([].slice.call(arguments));
}
};
// Custom dimensions
GA('set', 'dimension1', data.some_profile_information1);
GA('set', 'dimension2', data.some_profile_information2);
GA('set', 'dimension3', data.some_profile_information3);
// Track event
GA('send', {
'hitType': 'event', // Required.
'eventCategory': 'page', // Required.
'eventAction': 'custom_download', // Required.
'eventLabel': data.the_title_of_downloaded_section,
'eventValue': 1
});
};
Then in Google Analytics I can have custom reports like:
Is it possible in Matomo to send custom dimensions with a custom event in order to have the same reports / behavior?
UPDATE:
UPDATE:
Tried like this, no data in reports of custom dimensions.
var MA = window._paq || function() {
// Matomo is not defined, log function arguments
if (window.console) {
console.log([].slice.call(arguments));
}
};
MA.push([
'trackEvent',
'page', // category
'my_custom_download', // action
data.item_title, // name
1, // value
{ // custom dimensions
dimension1: data.dim1,
dimension2: data.dim2,
dimension3: data.dim3
}
]);
And this is from docs:
_paq.push(['trackEvent', category, action, name, value, {dimension1: 'DimensionValue'}]);
Upvotes: 0
Views: 320
Reputation: 113345
The solution you mention should work, but a delay may appear (about one hour, for instance):
var MA = window._paq || function() {
// Matomo is not defined, log function arguments
if (window.console) {
console.log([].slice.call(arguments));
}
};
MA.push([
'trackEvent',
'page', // category
'my_custom_download', // action
data.item_title, // name
1, // value
{ // custom dimensions
dimension1: data.dim1,
dimension2: data.dim2,
dimension3: data.dim3
}
]);
Upvotes: 2