Skip to content

Commit

Permalink
Refactor: no need to pass through the ahoy event name dynamically. (f…
Browse files Browse the repository at this point in the history
…orem#18498)

* refactor: the name does not need to be passed through dynamically

* refactor: the name does not need to be passed through dynamically

* chore: remove name from the js doc
  • Loading branch information
Ridhwana authored and TERNOX committed Jan 5, 2025
1 parent 958c7c3 commit 64ae047
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/javascript/packs/articlePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,5 @@ targetNode && embedGists(targetNode);

initializeUserSubscriptionLiquidTagContent();
// Temporary Ahoy Stats for comment section clicks on controls
trackCommentClicks('comments', 'Comment section click');
trackCommentClicks('comments');
trackCommentsSectionDisplayed();
11 changes: 2 additions & 9 deletions app/javascript/packs/base.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,5 @@ if (document.location.pathname === '/admin/creator_settings/new') {
loadCreatorSettings();
}

trackCreateAccountClicks(
'authentication-hamburger-actions',
'Clicked on Create Account',
);

trackCreateAccountClicks(
'authentication-top-nav-actions',
'Clicked on Create Account',
);
trackCreateAccountClicks('authentication-hamburger-actions');
trackCreateAccountClicks('authentication-top-nav-actions');
7 changes: 2 additions & 5 deletions app/javascript/packs/homePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,5 @@ InstantClick.on('change', () => {
});
InstantClick.init();

trackCreateAccountClicks('sidebar-wrapper-left', 'Clicked on Create Account');
trackCreateAccountClicks(
'authentication-feed-actions',
'Clicked on Create Account',
);
trackCreateAccountClicks('sidebar-wrapper-left');
trackCreateAccountClicks('authentication-feed-actions');
10 changes: 4 additions & 6 deletions app/javascript/utilities/ahoy/trackEvents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import ahoy from 'ahoy.js';
// * passed in element.
// *
// * @param {string} elementId A unique identifier to identify the element that is being tracked
// * @param {string} name The name of the event
// */
export function trackCommentClicks(elementId, name) {
export function trackCommentClicks(elementId) {
document
.getElementById(elementId)
?.addEventListener('click', ({ target }) => {
const relevantNode = getTrackingNode(target, '[data-tracking-name]');

if (relevantNode) {
ahoy.track(name, {
ahoy.track('Comment section click', {
page: location.href,
element: relevantNode.dataset?.trackingName,
});
Expand All @@ -25,15 +24,14 @@ export function trackCommentClicks(elementId, name) {
// * passed in element.
// *
// * @param {string} elementId A unique identifier to identify the element that is being tracked
// * @param {string} name The name of the event
// */
export function trackCreateAccountClicks(elementId, name) {
export function trackCreateAccountClicks(elementId) {
document
.getElementById(elementId)
?.addEventListener('click', ({ target }) => {
const relevantNode = getTrackingNode(target, '[data-tracking-id]');
if (relevantNode) {
ahoy.track(name, {
ahoy.track('Clicked on Create Account', {
version: 0.1,
page: location.href,
source: relevantNode.dataset?.trackingSource,
Expand Down

0 comments on commit 64ae047

Please sign in to comment.