Skip to content

Commit

Permalink
PubMatic Bid Adapter : passing property connectiontype in device obje…
Browse files Browse the repository at this point in the history
…ct (prebid#11373)

* Added support of connectiontype in ortb device object

* Fixed linting issues

* Fixed linting issues

* Removed duplicate test case
  • Loading branch information
kapil-tuptewar authored and mefjush committed Apr 25, 2024
1 parent 31e8688 commit b1c0eba
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
22 changes: 21 additions & 1 deletion modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,25 @@ function _handleCustomParams(params, conf) {
return conf;
}

export function getDeviceConnectionType() {
let connection = window.navigator && (window.navigator.connection || window.navigator.mozConnection || window.navigator.webkitConnection);
switch (connection?.effectiveType) {
case 'ethernet':
return 1;
case 'wifi':
return 2;
case 'slow-2g':
case '2g':
return 4;
case '3g':
return 5;
case '4g':
return 6;
default:
return 0;
}
}

function _createOrtbTemplate(conf) {
return {
id: '' + new Date().getTime(),
Expand All @@ -280,7 +299,8 @@ function _createOrtbTemplate(conf) {
dnt: (navigator.doNotTrack == 'yes' || navigator.doNotTrack == '1' || navigator.msDoNotTrack == '1') ? 1 : 0,
h: screen.height,
w: screen.width,
language: navigator.language
language: navigator.language,
connectiontype: getDeviceConnectionType()
},
user: {},
ext: {}
Expand Down
25 changes: 24 additions & 1 deletion test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { spec, checkVideoPlacement, _getDomainFromURL, assignDealTier, prepareMetaObject } from 'modules/pubmaticBidAdapter.js';
import { spec, checkVideoPlacement, _getDomainFromURL, assignDealTier, prepareMetaObject, getDeviceConnectionType } from 'modules/pubmaticBidAdapter.js';
import * as utils from 'src/utils.js';
import { config } from 'src/config.js';
import { createEidsArray } from 'modules/userId/eids.js';
Expand Down Expand Up @@ -2964,6 +2964,14 @@ describe('PubMatic adapter', function () {
expect(data.imp[0].ext.ae).to.equal(1);
});
});

it('should send connectiontype parameter if browser contains navigator.connection property', function () {
const bidRequest = spec.buildRequests(bidRequests);
let data = JSON.parse(bidRequest.data);
if (window.navigator && window.navigator.connection) {
expect(data.device).to.include.any.keys('connectiontype');
}
});
});

it('Request params dctr check', function () {
Expand Down Expand Up @@ -4020,6 +4028,21 @@ describe('PubMatic adapter', function () {
});
});

describe('getDeviceConnectionType', function() {
it('is a function', function(done) {
getDeviceConnectionType.should.be.a('function');
done();
});

it('should return matched value if navigator.connection is present', function(done) {
const connectionValue = getDeviceConnectionType();
if (window?.navigator?.connection) {
expect(connectionValue).to.be.a('number');
}
done();
});
});

if (FEATURES.VIDEO) {
describe('Checking for Video.Placement property', function() {
let sandbox, utilsMock;
Expand Down

0 comments on commit b1c0eba

Please sign in to comment.