Skip to content

Commit

Permalink
Magnite Analytics Adapter : data deletion function (prebid#9351)
Browse files Browse the repository at this point in the history
* add onDeletionRequest functionality to Magnite adapter

* Magnite add onDataDeletionRequest unit testing
  • Loading branch information
spotxslagle committed Dec 21, 2022
1 parent e2cfc18 commit b468831
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
10 changes: 9 additions & 1 deletion modules/magniteAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,15 @@ magniteAdapter.disableAnalytics = function () {
accountId = undefined;
resetConfs();
magniteAdapter.originDisableAnalytics();
}
};

magniteAdapter.onDataDeletionRequest = function () {
if (storage.localStorageIsEnabled()) {
storage.removeDataFromLocalStorage(COOKIE_NAME);
} else {
throw Error('Unable to access local storage, no data deleted');
}
};

magniteAdapter.MODULE_INITIALIZED_TIME = Date.now();
magniteAdapter.referrerHostname = '';
Expand Down
50 changes: 36 additions & 14 deletions test/spec/modules/magniteAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ const ANALYTICS_MESSAGE = {
describe('magnite analytics adapter', function () {
let sandbox;
let clock;
let getDataFromLocalStorageStub, setDataInLocalStorageStub, localStorageIsEnabledStub;
let getDataFromLocalStorageStub, setDataInLocalStorageStub, localStorageIsEnabledStub, removeDataFromLocalStorageStub;
let gptSlot0;
let gptSlotRenderEnded0;
beforeEach(function () {
Expand All @@ -325,6 +325,7 @@ describe('magnite analytics adapter', function () {
getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage');
setDataInLocalStorageStub = sinon.stub(storage, 'setDataInLocalStorage');
localStorageIsEnabledStub = sinon.stub(storage, 'localStorageIsEnabled');
removeDataFromLocalStorageStub = sinon.stub(storage, 'removeDataFromLocalStorage')
sandbox = sinon.sandbox.create();

localStorageIsEnabledStub.returns(true);
Expand Down Expand Up @@ -355,6 +356,7 @@ describe('magnite analytics adapter', function () {
getDataFromLocalStorageStub.restore();
setDataInLocalStorageStub.restore();
localStorageIsEnabledStub.restore();
removeDataFromLocalStorageStub.restore();
magniteAdapter.disableAnalytics();
});

Expand Down Expand Up @@ -1932,19 +1934,21 @@ describe('magnite analytics adapter', function () {
});
});

it('getHostNameFromReferer correctly grabs hostname from an input URL', function () {
let inputUrl = 'https://www.prebid.org/some/path?pbjs_debug=true';
expect(getHostNameFromReferer(inputUrl)).to.equal('www.prebid.org');
inputUrl = 'https://www.prebid.com/some/path?pbjs_debug=true';
expect(getHostNameFromReferer(inputUrl)).to.equal('www.prebid.com');
inputUrl = 'https://prebid.org/some/path?pbjs_debug=true';
expect(getHostNameFromReferer(inputUrl)).to.equal('prebid.org');
inputUrl = 'http://xn--p8j9a0d9c9a.xn--q9jyb4c/';
expect(typeof getHostNameFromReferer(inputUrl)).to.equal('string');

// not non-UTF char's in query / path which break if noDecodeWholeURL not set
inputUrl = 'https://prebid.org/search_results/%95x%8Em%92%CA/?category=000';
expect(getHostNameFromReferer(inputUrl)).to.equal('prebid.org');
describe('getHostNameFromReferer', () => {
it('correctly grabs hostname from an input URL', function () {
let inputUrl = 'https://www.prebid.org/some/path?pbjs_debug=true';
expect(getHostNameFromReferer(inputUrl)).to.equal('www.prebid.org');
inputUrl = 'https://www.prebid.com/some/path?pbjs_debug=true';
expect(getHostNameFromReferer(inputUrl)).to.equal('www.prebid.com');
inputUrl = 'https://prebid.org/some/path?pbjs_debug=true';
expect(getHostNameFromReferer(inputUrl)).to.equal('prebid.org');
inputUrl = 'http://xn--p8j9a0d9c9a.xn--q9jyb4c/';
expect(typeof getHostNameFromReferer(inputUrl)).to.equal('string');

// not non-UTF char's in query / path which break if noDecodeWholeURL not set
inputUrl = 'https://prebid.org/search_results/%95x%8Em%92%CA/?category=000';
expect(getHostNameFromReferer(inputUrl)).to.equal('prebid.org');
});
});

describe(`handle currency conversions`, () => {
Expand Down Expand Up @@ -1985,4 +1989,22 @@ describe('magnite analytics adapter', function () {
expect(bidResponseObj.bidPriceUSD).to.equal(0);
});
});

describe('onDataDeletionRequest', () => {
it('attempts to delete the magnite cookie when local storage is enabled', () => {
magniteAdapter.onDataDeletionRequest();

expect(removeDataFromLocalStorageStub.getCall(0).args[0]).to.equal('mgniSession');
});

it('throws an error if it cannot access the cookie', (done) => {
localStorageIsEnabledStub.returns(false);
try {
magniteAdapter.onDataDeletionRequest();
} catch (error) {
expect(error.message).to.equal('Unable to access local storage, no data deleted');
done();
}
})
});
});

0 comments on commit b468831

Please sign in to comment.