-
Notifications
You must be signed in to change notification settings - Fork 216
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
Merged
obulat
merged 8 commits into
WordPress:main
from
masif2002:analytics-event-BACK_TO_SEARCH
May 2, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5145046
Add analytic event: BACK_TO_SEARCH
masif2002 6992eb4
Added required props to component
masif2002 24c3f3f
Lint
obulat 93b40b9
Update frontend/src/components/VBackToSearchResultsLink.vue
obulat 5037f77
Use searchType instead of mediaType; add mousedown; add tests
obulat 15c3c08
Use UI to turn on Analytics
obulat 8d85236
Update frontend/src/components/meta/VBackToSearchResultsLink.stories.mdx
obulat 5d03035
Apply changes from code review
obulat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||
import type { MediaType } from "~/constants/media" | ||||||
import type { MediaType, SearchType } from "~/constants/media" | ||||||
import type { ReportReason } from "~/constants/content-report" | ||||||
|
||||||
/** | ||||||
|
@@ -26,6 +26,17 @@ export type Events = { | |||||
/** the identifier of the image */ | ||||||
identifier: string | ||||||
} | ||||||
/** | ||||||
* Click on the 'back to search' link on a single result | ||||||
* | ||||||
* - 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 commentThe reason will be displayed to describe this comment to others. Learn more. Small grammar nit.
Suggested change
|
||||||
id: string | ||||||
/** The content type being searched (can include All content) */ | ||||||
searchType: SearchType | ||||||
} | ||||||
/** | ||||||
* Description: The user clicks the CTA button to the external source to use the image | ||||||
* Questions: | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
frontend/test/unit/specs/components/v-back-to-search-results-link.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { createLocalVue } from "@vue/test-utils" | ||
import { fireEvent, render } from "@testing-library/vue" | ||
|
||
import { PiniaVuePlugin, createPinia } from "~~/test/unit/test-utils/pinia" | ||
|
||
import { useAnalytics } from "~/composables/use-analytics" | ||
|
||
import VBackToSearchResultsLink from "~/components/VBackToSearchResultsLink.vue" | ||
|
||
jest.mock("~/composables/use-analytics", () => ({ | ||
useAnalytics: jest.fn(), | ||
})) | ||
|
||
const localVue = createLocalVue() | ||
localVue.use(PiniaVuePlugin) | ||
describe("VBackToSearchResultsLink", () => { | ||
it("should send analytics event when clicked", async () => { | ||
const sendCustomEventMock = jest.fn() | ||
|
||
useAnalytics.mockImplementation(() => ({ | ||
sendCustomEvent: sendCustomEventMock, | ||
})) | ||
obulat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const propsData = { | ||
id: "123", | ||
href: "/search", | ||
} | ||
|
||
const screen = render(VBackToSearchResultsLink, { | ||
localVue, | ||
pinia: createPinia(), | ||
propsData, | ||
}) | ||
const link = screen.getByText("single-result.back") | ||
|
||
await fireEvent.click(link) | ||
|
||
expect(sendCustomEventMock).toHaveBeenCalledWith("BACK_TO_SEARCH", { | ||
id: propsData.id, | ||
searchType: "all", | ||
}) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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