Skip to content

Commit

Permalink
feat(topics): add toggle event
Browse files Browse the repository at this point in the history
  • Loading branch information
nsantacruz committed Aug 27, 2024
1 parent 5d3649f commit 3b53f88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion static/js/Story.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ StoryFrame.propTypes = {
const SummarizedStoryFrame = ({cls, cardColor, collapsibleSummary, children}) => {
return (
<StoryFrame cls={cls}>
<details><summary>{collapsibleSummary}</summary>{children}</details>
<details data-anl-event="package_toggle:toggle" data-anl-from="derived"><summary>{collapsibleSummary}</summary>{children}</details>
</StoryFrame>
)};
SummarizedStoryFrame.propTypes = {
Expand Down
14 changes: 14 additions & 0 deletions static/js/analyticsEventTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ const AnalyticsEventTracker = (function() {
return b;
}

function _getDerivedData(event) {
/**
* Return data that can be derived directly from `event`
*/
if (event.type === "toggle") {
return {
from: event.target.open ? "closed" : "open",
to: event.target.open ? "open" : "closed"
};
}
return {};
}

function _handleAnalyticsEvent(event) {
const anlEvent = _getAnalyticsEvent(event);
if (!anlEvent) { return; }
Expand All @@ -123,6 +136,7 @@ const AnalyticsEventTracker = (function() {
// make sure that analytics fields that are defined lower down aren't overwritten by ones defined higher in the DOM tree
anlEventData = _mergeObjectsWithoutOverwrite(currAnlEventData, anlEventData);
} while (currElem?.parentNode);
anlEventData = {...anlEventData, ..._getDerivedData(event)};

if (!_isValidAnalyticsObject(anlEventData)) { return; }

Expand Down

0 comments on commit 3b53f88

Please sign in to comment.