@salesforcedevs/dx-components 1.3.244-alpha2 → 1.3.245-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -14,6 +14,7 @@ export default class CardBlogPost extends LightningElement {
|
|
|
14
14
|
@api title!: string;
|
|
15
15
|
@api authors?: Array<any> | null = null;
|
|
16
16
|
@api origin?: string = "wordpress";
|
|
17
|
+
@api clickEvent?: () => void;
|
|
17
18
|
|
|
18
19
|
// LWC is being compiled so that datetime is being interpreted as date-time
|
|
19
20
|
// ONLY from from the implementation in dx-card-blog-post-provider
|
|
@@ -22,6 +23,10 @@ export default class CardBlogPost extends LightningElement {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
private onLinkClick(event: Event) {
|
|
26
|
+
if (this.clickEvent) {
|
|
27
|
+
this.clickEvent();
|
|
28
|
+
}
|
|
29
|
+
|
|
25
30
|
const payload = {
|
|
26
31
|
click_text: this.title,
|
|
27
32
|
click_url: `${window.location.origin}${this.href}`,
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import { LightningElement, api } from "lwc";
|
|
2
2
|
|
|
3
3
|
const SEARCH_HUB = "developerWebsiteBlogs";
|
|
4
|
+
|
|
5
|
+
interface Recommendation {
|
|
6
|
+
originalCoveoData: {
|
|
7
|
+
uri: string;
|
|
8
|
+
title: string;
|
|
9
|
+
searchUid: string;
|
|
10
|
+
raw: {
|
|
11
|
+
permanentId: string;
|
|
12
|
+
};
|
|
13
|
+
"@source": string;
|
|
14
|
+
};
|
|
15
|
+
clickEvent: () => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
4
18
|
export default class CoveoRecommendations extends LightningElement {
|
|
5
19
|
@api coveoAuthToken!: string;
|
|
6
20
|
@api coveoOrganizationId!: string;
|
|
7
21
|
|
|
8
|
-
_recommendations = [] as
|
|
22
|
+
_recommendations = [] as Recommendation[];
|
|
9
23
|
|
|
10
24
|
private get recommendations(): any[] {
|
|
11
25
|
return this._recommendations || [];
|
|
@@ -46,10 +60,17 @@ export default class CoveoRecommendations extends LightningElement {
|
|
|
46
60
|
|
|
47
61
|
const blogDataLoadTasks = results
|
|
48
62
|
.slice(0, 3)
|
|
49
|
-
.map(async (rec: any) => {
|
|
63
|
+
.map(async (rec: any, index: number) => {
|
|
50
64
|
const slug = rec.uri.split("/").pop();
|
|
51
65
|
const blogDataUrl = `https://developer.salesforce.com/blogs/wp-json/wp/v2/posts?slug=${slug}&state=publish&_embed=wp:featuredmedia`;
|
|
52
|
-
|
|
66
|
+
const wordPressData = (
|
|
67
|
+
await (await fetch(blogDataUrl)).json()
|
|
68
|
+
)[0];
|
|
69
|
+
wordPressData.originalCoveoData = rec;
|
|
70
|
+
wordPressData.originalCoveoData.searchUid =
|
|
71
|
+
json.searchUid;
|
|
72
|
+
wordPressData.clickEvent =
|
|
73
|
+
this.buildClickAnalyticsLogger(index);
|
|
53
74
|
});
|
|
54
75
|
this._recommendations = await Promise.all(
|
|
55
76
|
blogDataLoadTasks
|
|
@@ -76,7 +97,7 @@ export default class CoveoRecommendations extends LightningElement {
|
|
|
76
97
|
originLevel1: SEARCH_HUB,
|
|
77
98
|
originLevel2: SEARCH_HUB,
|
|
78
99
|
actionCause: "recommendationInterfaceLoad",
|
|
79
|
-
queryText: "",
|
|
100
|
+
queryText: "", // This has to be included, but is empty, because recommendations use the 'search' endpoint with an empty query string
|
|
80
101
|
responseTime: time,
|
|
81
102
|
searchQueryUid: uid
|
|
82
103
|
};
|
|
@@ -92,4 +113,38 @@ export default class CoveoRecommendations extends LightningElement {
|
|
|
92
113
|
}
|
|
93
114
|
);
|
|
94
115
|
};
|
|
116
|
+
|
|
117
|
+
buildClickAnalyticsLogger = (index: number) => () => {
|
|
118
|
+
const payload = {
|
|
119
|
+
anonymous: true,
|
|
120
|
+
documentPosition: index,
|
|
121
|
+
documentTitle: this._recommendations[index].originalCoveoData.title,
|
|
122
|
+
documentUrl: this._recommendations[index].originalCoveoData.uri,
|
|
123
|
+
language: "en",
|
|
124
|
+
originLevel1: SEARCH_HUB,
|
|
125
|
+
originLevel2: SEARCH_HUB,
|
|
126
|
+
actionCause: "recommendationOpen",
|
|
127
|
+
queryText: "", // This has to be included, but is empty, because recommendations use the 'search' endpoint with an empty query string
|
|
128
|
+
searchQueryUid: this._recommendations[index].originalCoveoData.uri,
|
|
129
|
+
sourceName:
|
|
130
|
+
this._recommendations[index].originalCoveoData["@source"],
|
|
131
|
+
customData: {
|
|
132
|
+
contentIDKey: "permanentId",
|
|
133
|
+
contentIDValue:
|
|
134
|
+
this._recommendations[index].originalCoveoData.raw
|
|
135
|
+
.permanentId
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
fetch(
|
|
139
|
+
`https://${this.coveoOrganizationId}.analytics.org.coveo.com/rest/ua/v15/analytics/click`,
|
|
140
|
+
{
|
|
141
|
+
headers: {
|
|
142
|
+
Authorization: `Bearer ${this.coveoAuthToken}`,
|
|
143
|
+
"Content-Type": "application/json"
|
|
144
|
+
},
|
|
145
|
+
method: "POST",
|
|
146
|
+
body: JSON.stringify(payload)
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
};
|
|
95
150
|
}
|