【问题标题】:Matomo - Location provider plugin and access to visit detailsMatomo - 位置提供程序插件和访问详细信息
【发布时间】:2019-08-15 06:26:13
【问题描述】:

我正在尝试编写我的第一个 Matomo 插件(位置提供程序),它将根据自定义维度列确定用户的位置。

到目前为止,我已经想出了这个代码:

<?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
    );
}

}

所以在 getLocation($info) 中我应该确定国家代码。 $info 只保存 IP 地址和浏览器语言。 我看到的所有位置提供程序插件都使用这两个属性之一来确定用户的国家/地区。

是否可以在 Location 提供中获取访问详细信息,尤其是自定义访问维度值?还是我应该以其他方式处理它?

谢谢

【问题讨论】:

    标签: plugins matomo location-provider


    【解决方案1】:

    使用Common::getrequestVar() 获取请求值。

    这是我使用自定义变量而不是自定义维度的示例:

        public function getLocation($info)
        {
            $country_code = 'us';
    
            $_cvar = Common::getRequestVar('_cvar', '{}');
    
            //in my case $_cvar string looks something like '{&quot;1&quot;:[&quot;COUNTRY&quot;,&quot;gb&quot;]}'
    
            $_cvar = html_entity_decode($_cvar);
            $decoded_cvars = json_decode($_cvar, true);
    
            if ($decoded_cvars !== NULL) {
              $custom_var = array();
    
              foreach($decoded_cvars as $var) {
                $custom_var[$var[0]] = $var[1];
              }
    
              if (array_key_exists('COUNTRY', $custom_var)) {
                $country_code = $custom_var['COUNTRY'];
              }
            }
    
            $location = array(
              self::COUNTRY_CODE_KEY => $country_code
            );
    
            self::completeLocationResult($location);
    
            return $location;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-07
      • 1970-01-01
      • 2019-01-21
      相关资源
      最近更新 更多