Skip to content

Commit b468831

Browse files
authored
Magnite Analytics Adapter : data deletion function (prebid#9351)
* add onDeletionRequest functionality to Magnite adapter * Magnite add onDataDeletionRequest unit testing
1 parent e2cfc18 commit b468831

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

modules/magniteAnalyticsAdapter.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,15 @@ magniteAdapter.disableAnalytics = function () {
643643
accountId = undefined;
644644
resetConfs();
645645
magniteAdapter.originDisableAnalytics();
646-
}
646+
};
647+
648+
magniteAdapter.onDataDeletionRequest = function () {
649+
if (storage.localStorageIsEnabled()) {
650+
storage.removeDataFromLocalStorage(COOKIE_NAME);
651+
} else {
652+
throw Error('Unable to access local storage, no data deleted');
653+
}
654+
};
647655

648656
magniteAdapter.MODULE_INITIALIZED_TIME = Date.now();
649657
magniteAdapter.referrerHostname = '';

test/spec/modules/magniteAnalyticsAdapter_spec.js

+36-14
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ const ANALYTICS_MESSAGE = {
306306
describe('magnite analytics adapter', function () {
307307
let sandbox;
308308
let clock;
309-
let getDataFromLocalStorageStub, setDataInLocalStorageStub, localStorageIsEnabledStub;
309+
let getDataFromLocalStorageStub, setDataInLocalStorageStub, localStorageIsEnabledStub, removeDataFromLocalStorageStub;
310310
let gptSlot0;
311311
let gptSlotRenderEnded0;
312312
beforeEach(function () {
@@ -325,6 +325,7 @@ describe('magnite analytics adapter', function () {
325325
getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage');
326326
setDataInLocalStorageStub = sinon.stub(storage, 'setDataInLocalStorage');
327327
localStorageIsEnabledStub = sinon.stub(storage, 'localStorageIsEnabled');
328+
removeDataFromLocalStorageStub = sinon.stub(storage, 'removeDataFromLocalStorage')
328329
sandbox = sinon.sandbox.create();
329330

330331
localStorageIsEnabledStub.returns(true);
@@ -355,6 +356,7 @@ describe('magnite analytics adapter', function () {
355356
getDataFromLocalStorageStub.restore();
356357
setDataInLocalStorageStub.restore();
357358
localStorageIsEnabledStub.restore();
359+
removeDataFromLocalStorageStub.restore();
358360
magniteAdapter.disableAnalytics();
359361
});
360362

@@ -1932,19 +1934,21 @@ describe('magnite analytics adapter', function () {
19321934
});
19331935
});
19341936

1935-
it('getHostNameFromReferer correctly grabs hostname from an input URL', function () {
1936-
let inputUrl = 'https://www.prebid.org/some/path?pbjs_debug=true';
1937-
expect(getHostNameFromReferer(inputUrl)).to.equal('www.prebid.org');
1938-
inputUrl = 'https://www.prebid.com/some/path?pbjs_debug=true';
1939-
expect(getHostNameFromReferer(inputUrl)).to.equal('www.prebid.com');
1940-
inputUrl = 'https://prebid.org/some/path?pbjs_debug=true';
1941-
expect(getHostNameFromReferer(inputUrl)).to.equal('prebid.org');
1942-
inputUrl = 'http://xn--p8j9a0d9c9a.xn--q9jyb4c/';
1943-
expect(typeof getHostNameFromReferer(inputUrl)).to.equal('string');
1944-
1945-
// not non-UTF char's in query / path which break if noDecodeWholeURL not set
1946-
inputUrl = 'https://prebid.org/search_results/%95x%8Em%92%CA/?category=000';
1947-
expect(getHostNameFromReferer(inputUrl)).to.equal('prebid.org');
1937+
describe('getHostNameFromReferer', () => {
1938+
it('correctly grabs hostname from an input URL', function () {
1939+
let inputUrl = 'https://www.prebid.org/some/path?pbjs_debug=true';
1940+
expect(getHostNameFromReferer(inputUrl)).to.equal('www.prebid.org');
1941+
inputUrl = 'https://www.prebid.com/some/path?pbjs_debug=true';
1942+
expect(getHostNameFromReferer(inputUrl)).to.equal('www.prebid.com');
1943+
inputUrl = 'https://prebid.org/some/path?pbjs_debug=true';
1944+
expect(getHostNameFromReferer(inputUrl)).to.equal('prebid.org');
1945+
inputUrl = 'http://xn--p8j9a0d9c9a.xn--q9jyb4c/';
1946+
expect(typeof getHostNameFromReferer(inputUrl)).to.equal('string');
1947+
1948+
// not non-UTF char's in query / path which break if noDecodeWholeURL not set
1949+
inputUrl = 'https://prebid.org/search_results/%95x%8Em%92%CA/?category=000';
1950+
expect(getHostNameFromReferer(inputUrl)).to.equal('prebid.org');
1951+
});
19481952
});
19491953

19501954
describe(`handle currency conversions`, () => {
@@ -1985,4 +1989,22 @@ describe('magnite analytics adapter', function () {
19851989
expect(bidResponseObj.bidPriceUSD).to.equal(0);
19861990
});
19871991
});
1992+
1993+
describe('onDataDeletionRequest', () => {
1994+
it('attempts to delete the magnite cookie when local storage is enabled', () => {
1995+
magniteAdapter.onDataDeletionRequest();
1996+
1997+
expect(removeDataFromLocalStorageStub.getCall(0).args[0]).to.equal('mgniSession');
1998+
});
1999+
2000+
it('throws an error if it cannot access the cookie', (done) => {
2001+
localStorageIsEnabledStub.returns(false);
2002+
try {
2003+
magniteAdapter.onDataDeletionRequest();
2004+
} catch (error) {
2005+
expect(error.message).to.equal('Unable to access local storage, no data deleted');
2006+
done();
2007+
}
2008+
})
2009+
});
19882010
});

0 commit comments

Comments
 (0)