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

Magnite Analytics Adapter : data deletion function #9351

Merged
merged 2 commits into from
Dec 21, 2022
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
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();
}
})
});
});