i trying write my first Matomo plugi n(Location provider) that will determine user's location based on custom dimension column.
So far I have came up with this code:
<?php
namespace Piwik\Plugins\LocationProviderCustom\LocationProvider;
use Piwik\Plugins\UserCountry\LocationProvider;
class CountryProvider extends LocationProvider {
public function getLocation($info) {
// custom_dimension_1 should be accessible here
$location = array(
self::COUNTRY_CODE_KEY => 'us'
);
self::completeLocationResult($location);
return $location;
}
public function isWorking() {
return true;
}
public function isAvailable() {
return true;
}
public function getSupportedLocationInfo() {
return array(
self::COUNTRY_CODE_KEY => true
);
}
public function getInfo() {
return array(
'id' => 'locationProviderCustom',
'title' => 'Location Provide',
'description' => '',
'order' => 5
);
}
}
So in getLocation($info) I should determine the country code. $info is holding just IP address and browser language. All of location provider plugings that I saw used one of those two properties to determine user's country.
Is it possible to get visit details and especially custom visit dimension values into the Location provide? Or should I approach it some other way?
Thanks
Use Common::getrequestVar() to get the request values.
Here's an example where I was using custom variable rather than custom dimensions: