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

ia analytics, move to 1% sampled bucket #1105

Merged
merged 6 commits into from
Nov 17, 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
2 changes: 2 additions & 0 deletions BookReaderDemo/IADemoBr.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ const initializeBookReader = (brManifest) => {
// we expect this at the global level
BookReaderJSIAinit(brManifest.data, options);

const isRestricted = brManifest.data.isRestricted;
window.dispatchEvent(new CustomEvent('contextmenu', { detail: { isRestricted } }));
if (customAutoflipParams.autoflip) {
br.autoToggle(customAutoflipParams);
}
Expand Down
4 changes: 2 additions & 2 deletions src/BookNavigator/book-navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ export class BookNavigator extends LitElement {
/** Display an element's context menu */
manageContextMenuVisibility(e) {
if (window.archive_analytics) {
window.archive_analytics?.send_event_no_sampling(
window.archive_analytics?.send_event(
'BookReader',
`contextmenu-${this.bookIsRestricted ? 'restricted' : 'unrestricted'}`,
e.target.classList.value
e.target?.classList?.value
);
}
if (!this.bookIsRestricted) {
Expand Down
2 changes: 1 addition & 1 deletion src/BookNavigator/volumes/volumes-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default class VolumesProvider {
if (!window.archive_analytics) {
return;
}
window.archive_analytics?.send_event_no_sampling(
window.archive_analytics?.send_event(
'BookReader',
`VolumesSort|${orderBy}`,
window.location.path,
Expand Down
34 changes: 19 additions & 15 deletions tests/jest/BookNavigator/book-navigator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ window.ResizeObserver = class ResizeObserver {
disconnect = sinon.fake()
};

beforeEach(() => {
window.archive_analytics = {
send_event_no_sampling: sinon.fake(),
send_event: sinon.fake()
};
});

afterEach(() => {
window.br = null;
fixtureCleanup();
Expand Down Expand Up @@ -516,8 +523,6 @@ describe('<book-navigator>', () => {
describe('Handles Restricted Books', () => {
describe('contextMenu is prevented when book is restricted', () => {
it('watches on `div.BRscreen`', async () => {
window.archive_analytics = { send_event_no_sampling: sinon.fake() };

const el = fixtureSync(container());
const brStub = {
options: { restricted: true },
Expand All @@ -529,9 +534,8 @@ describe('<book-navigator>', () => {
const elSpy = sinon.spy(el.manageContextMenuVisibility);
await el.elementUpdated;

expect(window.archive_analytics.send_event_no_sampling.called).toEqual(
false
);
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(false);
expect(window.archive_analytics.send_event.called).toEqual(false);
expect(elSpy.called).toEqual(false);

const body = document.querySelector('body');
Expand All @@ -550,14 +554,13 @@ describe('<book-navigator>', () => {

// analytics fires
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(
true
false
);
expect(window.archive_analytics.send_event.called).toEqual(true);
// we prevent default
expect(preventDefaultSpy.called).toEqual(true);
});
it('watches on `img.BRpageimage`', async () => {
window.archive_analytics = { send_event_no_sampling: sinon.fake() };

const el = fixtureSync(container());
const brStub = {
options: { restricted: true },
Expand All @@ -568,9 +571,8 @@ describe('<book-navigator>', () => {

await el.elementUpdated;

expect(window.archive_analytics.send_event_no_sampling.called).toEqual(
false
);
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(false);
expect(window.archive_analytics.send_event.called).toEqual(false);

const body = document.querySelector('body');
// const element stub for img.BRpageimage
Expand All @@ -586,14 +588,13 @@ describe('<book-navigator>', () => {
imgBRpageimage.dispatchEvent(contextMenuEvent);

// analytics fires
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(true);
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(false);
expect(window.archive_analytics.send_event.called).toEqual(true);
// we prevent default
expect(preventDefaultSpy.called).toEqual(true);
});
});
it('Allows unrestricted books access to context menu', async () => {
window.archive_analytics = { send_event_no_sampling: sinon.fake() };

const el = fixtureSync(container());
const brStub = {
options: { restricted: false },
Expand All @@ -607,6 +608,8 @@ describe('<book-navigator>', () => {
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(
false
);
expect(window.archive_analytics.send_event.called).toEqual(false);


const body = document.querySelector('body');
// const element stub for img.BRpageimage
Expand All @@ -622,7 +625,8 @@ describe('<book-navigator>', () => {
imgBRpageimage.dispatchEvent(contextMenuEvent);

// analytics fires
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(true);
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(false);
expect(window.archive_analytics.send_event.called).toEqual(true);
// we do not prevent default
expect(preventDefaultSpy.called).toEqual(false);
});
Expand Down