This example shows how to access the 'match metrics' assocaited with
a result from 51Degrees device detection.
Match metrics are various properties that indicate the level of confidence
that the supplied evidence corresponds to the result that has been returned.
This example requires a local data file. The free 'Lite' data file can be acquired by
pulling the git submodules under this repository (run `git submodule update --recursive`)
or from the device-detection-data
GitHub repository.
The Lite data file is only used for illustration, and has limited accuracy and capabilities.
Find out about the more capable data files that are available on our
pricing page
In this example we create an on premise 51Degrees device detection pipeline, in order to do this you will need a copy of the 51Degrees on-premise library and need to make the following additions to your php.ini file
When running under process manager such as Apache MPM or php-fpm, make sure to set performance_profile to MaxPerformance by making the following addition to php.ini file. More details can be found in README.
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36
Matched User-Agent:
Id: 15364-38914-97847-0
Difference: 0
Drift: 0
Method: 0
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114
Matched User-Agent:
Id: 12280-81243-82102-0
Difference: 0
Drift: 0
Method: 0
<?php
require(__dir__ . "/../../vendor/autoload.php");
$device = new DeviceDetectionOnPremise(array(
"performanceProfile" => "LowMemory",
"usePredictiveGraph" => true,
"usePerformanceGraph" => false
));
$pipeline = new PipelineBuilder();
$pipeline = $pipeline->add($device)->build();
function check_metrics($userAgent, $pipeline){
$flowData = $pipeline->createFlowData();
$flowData->evidence->set("header.user-agent", $userAgent);
$result = $flowData->process();
$device = $result->device;
echo "User-Agent: " . $userAgent . "</br>\n";
echo "Matched User-Agent: " .
$device->useragents->value[0] . "</br>\n";
echo "Id: " . $device->deviceId->value . "</br>\n";
echo "Difference: " . $device->difference->value . "</br>\n";
echo "Drift: " . $device->drift->value . "</br>\n";
echo "Method: " . $device->method->value . "</br>\n";
echo "</br>\n";
echo "</br>\n";
}
$desktopUA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36';
$iPhoneUA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114';
check_metrics($desktopUA, $pipeline);
check_metrics($iPhoneUA, $pipeline);