Skip to content

Commit

Permalink
chore: 991 Add pan and zoom analytics events (#992)
Browse files Browse the repository at this point in the history
  • Loading branch information
tihuan authored Jun 18, 2024
1 parent 339f7c9 commit 34824b9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/src/analytics/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export enum EVENTS {
EXPLORER_IMAGE_SELECT = "EXPLORER_IMAGE_SELECT",
EXPLORER_IMAGE_DESELECT = "EXPLORER_IMAGE_DESELECT",
EXPLORER_RE_CENTER_EMBEDDING = "EXPLORER_RE_CENTER_EMBEDDING",
EXPLORER_ZOOMED = "EXPLORER_ZOOMED",
EXPLORER_PANNED = "EXPLORER_PANNED",

WMG_CLICK_NAV = "WMG_CLICK_NAV",
COLLECTIONS_CLICK_NAV = "COLLECTIONS_CLICK_NAV",
Expand Down
36 changes: 36 additions & 0 deletions client/src/util/camera.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { vec2, mat3 } from "gl-matrix";
import { MouseEvent } from "react";
import { Point, Viewer } from "openseadragon";
import { debounce } from "lodash";
import clamp from "./clamp";
import { THROTTLE_MS, SCALE_MAX } from "./constants";
import { EVENTS } from "../analytics/events";
import { track } from "../analytics";

const ANALYTICS_PAN_ZOOM_DEBOUNCE_MS = 100;

const EPSILON = 0.000001;

Expand Down Expand Up @@ -80,6 +85,8 @@ export class Camera {
prevOffsetX?: number;
prevOffsetY?: number;
}): void {
this.debouncedPanTrack();

const m = this.viewMatrix;

/**
Expand Down Expand Up @@ -125,6 +132,16 @@ export class Camera {
}
}

debouncedPanTrack = debounce(
() => {
track(EVENTS.EXPLORER_PANNED);
},
ANALYTICS_PAN_ZOOM_DEBOUNCE_MS,
{
trailing: true,
}
);

goHome(openseadragon: Viewer | null = null) {
// Reset the custom layer's transformation matrix to the identity matrix
mat3.identity(this.viewMatrix);
Expand Down Expand Up @@ -296,9 +313,28 @@ export class Camera {
offsetY: offset[1],
});

this.debouncedZoomTrack();

return true;
}

debouncedZoomTrack = debounce(
() => {
const distance = this.distance();

/**
* (thuang): Product requirement - Don't track zoom events when we're zooming out
*/
if (distance < 1) return;

track(EVENTS.EXPLORER_ZOOMED, { zoomLevel: Math.round(distance) });
},
ANALYTICS_PAN_ZOOM_DEBOUNCE_MS,
{
trailing: true,
}
);

handleEvent(
e: MouseEvent<HTMLCanvasElement, MouseEvent<Element, MouseEvent>>,
projectionTF: mat3,
Expand Down

0 comments on commit 34824b9

Please sign in to comment.