-
Notifications
You must be signed in to change notification settings - Fork 11
ksearch: upgrade to Events API #508
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
base: main
Are you sure you want to change the base?
Conversation
This PR upgrades our analytics calls to the next major version, also called the Events API. As part of this work, analytics calls have changed shape, and some deprecated properties have been dropped. J=WAT-4651 TEST=auto,manual Updated auto tests. Ran test site locally and saw events all the way to snowflake.
Current unit coverage is 91.4992993928071% |
@@ -1,5 +1,5 @@ | |||
import React, { PropsWithChildren } from 'react'; | |||
import { provideAnalytics, AnalyticsConfig } from '@yext/analytics'; |
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 AnalyticsConfig has changed shape in the new analytics, the old one was actually very search specific and had properties like experienceKey - the new one is very high level and only requires an auth type and an auth key. I think because of this alone this is breaking.
queryId, | ||
verticalKey: verticalKey || '', | ||
url, | ||
fieldName, |
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 drop 'searcher' and 'fieldName'
verticalKey: verticalKey, | ||
newPage, | ||
currentPage, | ||
totalPageCount |
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 drop all three of these page-related values.
currentPage: number, | ||
totalPageCount: number | ||
) => void { | ||
export function usePaginationAnalytics(): () => void { |
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 function changes signature
analytics?.report({ | ||
type: 'AUTO_COMPLETE_SELECTION', | ||
...(queryId && { queryId }), | ||
suggestedSearchText |
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 drop suggestedSearchText
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.
That's interesting, seems like it'd be a pretty relevant piece of data for this
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.
How do you mean? Interesting that analytics dropped it from their new system, or that I followed it?
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.
Interesting that analytics dropped it. We should ofc follow whatever their system supports / expects
@@ -90,10 +93,19 @@ export function SectionHeader(props: SectionHeaderProps): JSX.Element { | |||
console.error('Unable to report a vertical view all event. Missing field: queryId.'); | |||
return; | |||
} | |||
if (!experienceKey) { |
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.
Do we need a check for locale
or searchId
? Or are those automatically set
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.
locale can be unset in the event payload so passing it possible undefined is ok. For searchId we could also add error handling if the searchId is not present.
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.
Hm as I think about it, our analytics are all based off query id now right? Probably not necessary to require the search id if we don't see that changing
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.
Actually trying to send an analytics event without search id crashes out, as I recall. My understanding was that the events are based on the first search id of a query, which is the same as the query id.
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.
Got it, so it seems necessary, but also that it should be automatically set elsewhere correct? Therefore not requiring any extra check here?
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 agree a check would be nice, and I will add it. Could you elaborate the second comment? What should be set, the searchId? Isn't that pulled from the meta state? I'm not sure we have any guarantees about that.
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.
Sorry maybe I was misunderstanding your prior comment. The way I read it was that the search id was being set as the query id by default somewhere up the chain in the SDK somewhere. Feel free to disregard. I agree adding a check is good then
analytics?.report({ | ||
type: 'AUTO_COMPLETE_SELECTION', | ||
...(queryId && { queryId }), | ||
suggestedSearchText |
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.
That's interesting, seems like it'd be a pretty relevant piece of data for this
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "@yext/search-ui-react", | |||
"version": "1.8.2", | |||
"version": "1.8.3", |
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.
My debounce change is 1.8.3 so this will have to change - I assume to 2.0.0 since this has breaking changes
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, this change is a draft.
@@ -90,10 +93,19 @@ export function SectionHeader(props: SectionHeaderProps): JSX.Element { | |||
console.error('Unable to report a vertical view all event. Missing field: queryId.'); | |||
return; | |||
} | |||
if (!experienceKey) { |
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.
Got it, so it seems necessary, but also that it should be automatically set elsewhere correct? Therefore not requiring any extra check here?
This PR upgrades our analytics calls to the next major version, also called the Events API. As part of this work, analytics calls have changed shape, and some deprecated properties have been dropped.
J=WAT-4651
TEST=auto,manual
Updated auto tests. Ran test site locally and saw events all the way to snowflake.