Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PubMatic Bid Adapter : passing property connectiontype in device object #11373

Merged
merged 6 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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