This example shows how to retrieve property meta data from 51Degrees
on-premise device detection.
This feature can be used to get information such as the category that
a property belongs to or the possible values a property can have.
(As of the current data file. If the data file is updated,
the possible values for a property can change)
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
Does user agent Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114 support svg? : true
Does user agent Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114 support video? : true
Does user agent Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114 support supportswebgl? : true
Does user agent Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114 support webp? : False
require((process.env.directory || __dirname) +
'/../../../deviceDetectionOnPremisePipelineBuilder');
const fs = require('fs');
const ExampleUtils = require(__dirname +
'/../exampleUtils').ExampleUtils;
const LITE_V_4_1_HASH = '51Degrees-LiteV4.1.hash';
const sliceLen = process.env.JEST_WORKER_ID === undefined ? 2 : process.argv.length;
const args = process.argv.slice(sliceLen);
const datafile = args.length > 0 ? args[0] :
ExampleUtils.
findFile(LITE_V_4_1_HASH);
if (!fs.existsSync(datafile)) {
console.error('Failed to find a device detection ' +
'data file. Make sure the device-detection-data ' +
'submodule has been updated by running ' +
'`git submodule update --recursive`.');
throw ("No data file at '" + datafile + "'");
}
performanceProfile: 'MaxPerformance',
dataFile: datafile,
autoUpdate: false
}).build();
pipeline.on('error', console.error);
const properties = pipeline.getElement('device').getProperties();
for (let property in properties) {
property = properties[property];
console.log(`Property ${property.name}, ${property.description}, of type ${property.type}`);
}
const getAllSupportedMedia = async function (userAgent) {
const flowData = pipeline.createFlowData();
flowData.evidence.add('header.user-agent', userAgent);
await flowData.process();
const supported = flowData.getWhere('category', 'Supported Media');
Object.entries(supported).forEach(([key, result]) => {
console.log(`Does user agent ${userAgent} support ${key}? : `);
if (result.hasValue) {
console.log(result.value);
} else {
console.log(result.noValueMessage);
}
});
};
const iPhoneUA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114';
getAllSupportedMedia(iPhoneUA);
const getMatchMetaData = async function (userAgent) {
const flowData = pipeline.createFlowData();
flowData.evidence.add('header.user-agent', userAgent);
await flowData.process();
if (flowData.device.deviceID && flowData.device.deviceID.hasValue) {
console.log('Device ID: ' + flowData.device.deviceID.value);
}
if (flowData.device.userAgents && flowData.device.userAgents.hasValue) {
console.log('Matched useragents' + flowData.device.userAgents.value);
}
if (flowData.device.difference && flowData.device.difference.hasValue) {
console.log('Difference' + flowData.device.difference.value);
}
if (flowData.device.method && flowData.device.method.hasValue) {
console.log('Method ' + flowData.device.method.value);
}
if (flowData.device.matchedNodes && flowData.device.matchedNodes.hasValue) {
console.log('Matched nodes' + flowData.device.matchedNodes.value);
}
};
getMatchMetaData(iPhoneUA);