Skip to content
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
40 changes: 9 additions & 31 deletions modules/insticatorBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {find} from '../src/polyfill.js';

const BIDDER_CODE = 'insticator';
const ENDPOINT = 'https://ex.ingage.tech/v1/openrtb'; // production endpoint
const USER_ID_KEY = 'hb_insticator_uid';
const USER_ID_KEY = 'instUid';
const USER_ID_COOKIE_EXP = 7776000000; // 90 days
const BID_TTL = 300; // 5 minutes
const GVLID = 910;
Expand All @@ -23,14 +23,10 @@ config.setDefaults({

function getUserId() {
let uid = localStorage.getItem(USER_ID_KEY);
if (uid && isUserIdValid(uid)) {
return uid;
}

uid = storage.getCookie(USER_ID_KEY);
if (uid && isUserIdValid(uid)) {
const expireIn = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString();
storage.setCookie(USER_ID_KEY, uid, expireIn);
const domain = window.location.hostname.match(/[^.]*\.[^.]{2,3}(?:\.[^.]{2,3})?$/mg);
Copy link

@rohanInsticator rohanInsticator May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add one more logic here to extract the top-level-domain from the hostname & use that as the cookie domain. This way we can share the cookie across publisher's subdomain?

Not sure if that regex match operation is already doing that or not.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the regex match is taking the top level domain

image

storage.setCookie(USER_ID_KEY, uid, expireIn, 'none', `.${domain}`);
return uid;
}

Expand All @@ -44,36 +40,15 @@ function isUserIdValid(uid) {
function generateUserId() {
const uid = generateUUID();

if (isLocalStoreEnabled()) {
localStorage.setItem(USER_ID_KEY, uid);
return uid;
}

if (isCookieEnabled()) {
const expireIn = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString();
storage.setCookie(USER_ID_KEY, uid, expireIn);
const domain = window.location.hostname.match(/[^.]*\.[^.]{2,3}(?:\.[^.]{2,3})?$/mg);
storage.setCookie(USER_ID_KEY, uid, expireIn, 'none', `.${domain}`);
}

return uid;
}

function isLocalStoreEnabled() {
let enabled = false;

try {
localStorage.setItem('prebid.localStoreTest', 'true');
enabled = Boolean(localStorage.getItem('prebid.localStoreTest'));
} catch (err) {
return false
} finally {
if (enabled) {
localStorage.removeItem('insticator.prebid.localStoreTest');
}
}

return enabled;
}

function isCookieEnabled() {
let enabled = false;

Expand Down Expand Up @@ -321,7 +296,10 @@ export const spec = {
buildRequests: function (validBidRequests, bidderRequest) {
const requests = [];
let endpointUrl = config.getConfig('insticator.endpointUrl') || ENDPOINT;
endpointUrl = endpointUrl.replace(/^http:/, 'https:');

if (endpointUrl.indexOf('localhost') === -1) {
endpointUrl = endpointUrl.replace(/^http:/, 'https:');
}

if (validBidRequests.length > 0) {
requests.push({
Expand Down
2 changes: 1 addition & 1 deletion test/spec/modules/insticatorBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ describe('InsticatorBidAdapter', function () {
const requests = spec.buildRequests([bidRequest], bidderRequest);
const data = JSON.parse(requests[0].data);

expect(data.user.buyeruid).to.equal(USER_ID_STUBBED);
expect(data.user.id).to.equal(USER_ID_STUBBED);
});
it('should return empty regs object if no gdprConsent is passed', function () {
const requests = spec.buildRequests([bidRequest], { ...bidderRequest, ...{ gdprConsent: false } });
Expand Down