Skip to content
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

Added case and article ids to AttachResult custom events #77

Merged
merged 3 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pages/attached_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<div class="coveo-result-frame">
<div class="CoveoResultActionsMenu">
<div class="CoveoQuickview"></div>
<div class="CoveoAttachResult" data-attach-caption="Attach" data-detach-caption="Detach"></div>
<div class="CoveoAttachResult" data-attach-caption="Attach" data-detach-caption="Detach" data-case-id="f00b4r"></div>
</div>
<div class="coveo-result-cell" style="vertical-align:top;text-align:center;width:32px;">
<span class="CoveoIcon" data-small="true" data-with-label="false"></span>
Expand Down
16 changes: 14 additions & 2 deletions src/components/AttachResult/AttachResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export interface IAttachResultOptions {
attachCaption?: string;
/** Specifies the tooltip displayed when the result is already attached. */
detachCaption?: string;
/** The field of the query result which represents the Article ID in the index, used for Usage Analytics purposes. */
articleIdField?: string;
/** Id of the record where the search is currently displayed, if any. */
caseId?: string;
/** The function that is called when the user wants to attach a result. */
attach?: (queryResult: IQueryResult) => Promise<void>;
/** The function called when the user wants to un-link a result. */
Expand Down Expand Up @@ -50,6 +54,10 @@ export class AttachResult extends Component {
detachCaption: ComponentOptions.buildStringOption({
defaultValue: l(`${AttachResult.ID}_Detach`)
}),
articleIdField: ComponentOptions.buildStringOption({
defaultValue: 'permanentid'
mikegron marked this conversation as resolved.
Show resolved Hide resolved
}),
caseId: ComponentOptions.buildStringOption(),
attach: ComponentOptions.buildCustomOption(
name => (result: IQueryResult) =>
new Promise<void>((resolve, reject) => {
Expand Down Expand Up @@ -116,6 +124,7 @@ export class AttachResult extends Component {
.attach(this.queryResult)
.then(() => {
this.attached = true;
this.usageAnalytics.logClickEvent(analyticsActionCauseList.caseAttach, {}, this.queryResult, this.element);
this.logAnalyticsCaseEvent(analyticsActionCauseList.caseAttach);
Coveo.$$(this.root).trigger(AttachResultEvents.Attach, { queryResult: this.queryResult } as IAttachResultEventArgs);
})
Expand Down Expand Up @@ -194,8 +203,11 @@ export class AttachResult extends Component {
let customData: IAnalyticsCaseAttachMeta = {
resultUriHash: this.queryResult.raw.urihash,
author: this.queryResult.raw.author,
articleID: null,
caseID: null
articleID:
this.options.articleIdField && this.queryResult.raw[this.options.articleIdField]
? this.queryResult.raw[this.options.articleIdField]
: null,
mikegron marked this conversation as resolved.
Show resolved Hide resolved
caseID: this.options.caseId
lbergeron marked this conversation as resolved.
Show resolved Hide resolved
};

this.usageAnalytics.logCustomEvent<IAnalyticsCaseDetachMeta>(cause, customData, this.root);
Expand Down