-
Notifications
You must be signed in to change notification settings - Fork 202
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
Analytics event: BACK_TO_SEARCH #1118
Analytics event: BACK_TO_SEARCH #1118
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is on the right path, but needs at least one additional change to make it work. Please pass the new id and media type props to the component in the image/_id/index.vue
and audio/_id/index.vue
page components. Please also add a unit test to confirm the analytics event is called when the component is clicked.
If possible, please also test the change locally to verify that it is working:
- Run
just frontend/up && just frontend/init
- Run the app locally:
just frontend/run dev
- Log into plausible by visiting http://0.0.0.0:50288 and using the default username and password
[email protected]
anddeploy
- Add the custom event as a goal in http://0.0.0.0:50288/localhost/settings/goals
- Verify that clicking the back to search link populates the goal on the main Plausible page for the localhost site (http://0.0.0.0:50288/localhost) at the bottom under the Goal Conversions section
@dhruvkb I'm writing a page for the docs site with this basic setup information so we can link it on these issues for adding new events. Otherwise, anyone who didn't review the PRs adding Plausible would be a little lost on how to start testing it locally.
It would probably also be worthwhile to have a quick PR to set up testing utilities like an easy mock to use to test the function is called as expected, to make it easier for new contributors, as the issues are marked as "good first issue".
Will make the changes and test it locally @sarayourfriend I have never written unit tests before. Is there something that can get me started on this? |
Sure. Openverse uses Their documentation is fairly comprehensive, and we have lots of examples in our repository for other tests. A good basic example for Openverse specifically is the test suite for We also use You'll need to "spy" on the Something like: jest.mock("~/composables/use-analytics", () => ({
useAnalytics: jest.fn(() => ({
sendCustomEvent: jest.fn()
})
}) Then you can import the mocked The mock for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@masif2002 thanks for the PR, it's on the right track but needs a little more work before it can be merged.
@@ -3,14 +3,18 @@ | |||
<VLink | |||
class="time inline-flex flex-row items-center gap-2 rounded-sm p-2 text-xs font-semibold text-dark-charcoal-70 pe-3 hover:text-dark-charcoal" | |||
v-bind="$attrs" | |||
@click="handleClick()" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When referring to an event handler function, the parenthesis are not used (because that would invoke the function).
@click="handleClick()" | |
@click="handleClick" |
@@ -26,9 +30,37 @@ export default defineComponent({ | |||
VIcon, | |||
VLink, | |||
}, | |||
props: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These must be added below the inheritAttrs
field to match the recommended option order.
Also, if you add new required props to a component, you will need to update the usage of that component. This particular component VBackToSearchResultsLink.vue
is used in the following locations, which need to be updated:
frontend/src/pages/audio/_id/index.vue
frontend/src/pages/image/_id/index.vue
frontend/src/components/meta/VBackToSearchResultsLink.stories.mdx
* - Are these links used much? Are they necessary? | ||
*/ | ||
BACK_TO_SEARCH: { | ||
/** The unique ID of the media */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small grammar nit.
/** The unique ID of the media */ | |
/** the unique ID of the media */ |
frontend/src/types/analytics.ts
Outdated
BACK_TO_SEARCH: { | ||
/** The unique ID of the media */ | ||
id: string | ||
/** The media type being searched */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small grammar nit.
/** The media type being searched */ | |
/** the media type being searched */ |
Hey @sarayourfriend .. I tried testing the changes locally. I set the |
Have you confirmed that the |
Nope, the function is not invoked on click.. I'm trying to figure out why |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -3,14 +3,18 @@ | |||
<VLink | |||
class="time inline-flex flex-row items-center gap-2 rounded-sm p-2 text-xs font-semibold text-dark-charcoal-70 pe-3 hover:text-dark-charcoal" | |||
v-bind="$attrs" | |||
@click="handleClick" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked out the PR locally and it seems like this handler is not being called, despite being perfectly ok from a code standpoint. In fact, the identical code from a different component VHomeGallery.vue
works just as expected.
@click="handleClick(image.identifier)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes Dhruv, the CLICK_HOME_GALLERY_IMAGE
gets fired as expected, but BACK_TO_SEARCH
event doesn't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll try to investigate, but in the meantime please feel free to work on another issue if you'd like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll try to investigate, but in the meantime please feel free to work on another issue if you'd like.
Sure, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution, @masif2002 !
I've tried debugging the issue locally. The link's click event is fired after the page transition is complete and the button is already unmounted. That's why the analytics event is not fired.
I found a (somewhat hacky) solution: we can add a mousedown.native
event to the VLink
component, and use that for firing the analytics event.
Here are the changes that worked for me locally:
--- a/frontend/src/components/VBackToSearchResultsLink.vue
+++ b/frontend/src/components/VBackToSearchResultsLink.vue
- @click="handleClick"
+ @mousedown="handleClick"
>
<VIcon :icon-path="chevronIcon" :rtl-flip="true" />
{{ $t("single-result.back") }}
diff --git a/frontend/src/components/VLink.vue b/frontend/src/components/VLink.vue
--- a/frontend/src/components/VLink.vue
+++ b/frontend/src/components/VLink.vue
@@ -5,6 +5,7 @@
:class="{ 'inline-flex flex-row items-center gap-2': showExternalIcon }"
:to="linkTo"
v-on="$listeners"
+ @mousedown.native="$emit('mousedown', $event)"
@click.native="$emit('click', $event)"
>
Awesome, that's good to know. How did you find out that the event is fired only after the page transition? |
Yea this one works, thank you! |
@obulat how does this work in |
In the |
Wow, that's great! But as @dhruvkb said, how does the analytics event work as is in |
I think I found the answer to this. When you click on a link on the home page, you navigate to a different page that has a different layout. The same is true when you click on a page link from a search page. However, here, we stay in the same layout. This is the only difference between the events. |
@obulat Does that mean that when navigating between base layouts, Vue is, for some reason, keeping the previous layout mounted behind the scenes until it finishes triggering the event? It's interesting that that is the only difference, but I'm super curious why having different layouts between the navigated pages causes the difference in behaviour... 🤔 |
dc1f52f
to
347ccc2
Compare
Apparently, this is a regression that happened in Vue 2.7.x: nuxt/nuxt#10593 and vuejs/vue#12781. I think with a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@masif2002, I rebased your PR onto main.
Because the CI did not start, I replaced the @click
with @mousedown
to trigger it. We might need to change it after testing.
This PR needs unit tests. Are you interested in writing them? You can find examples in #1180. If not, please let us know and we can help finish your work in this PR.
Hey @obulat ! I'm swamped right now and won't be able to write the unit tests for this PR. Thanks for offering to help out, though - please go ahead and take care of it. |
Thank you for quick response, @masif2002! I'll add tests, then. You are always welcome to contribute when you have more time 😃 |
frontend/src/components/meta/VBackToSearchResultsLink.stories.mdx
Outdated
Show resolved
Hide resolved
e31bc27
to
19e4dfc
Compare
19e4dfc
to
8d85236
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just small questions but no blockers. Questions are for @obulat, to be clear.
frontend/test/unit/specs/components/v-back-to-search-results-link.spec.js
Show resolved
Hide resolved
73fe26c
to
5d03035
Compare
Fixes
Fixes #1087 by @dhruvkb
Description
BACK_TO_SEARCH
event to the Events type.VBackToSearchResultsLink.vue
using theuseAnalytics
composable.