@reactionary/provider-algolia 0.3.1 → 0.3.2
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/README.md
CHANGED
|
@@ -38,11 +38,19 @@ You can have more, for use with facets, and additional searchable fields, but th
|
|
|
38
38
|
|
|
39
39
|
The `objectID` corrosponds to your productIdentifier, and `variantID` should match your SKU
|
|
40
40
|
|
|
41
|
+
## Analytics
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
The Algolia analytics provider maps the following tracked event types to data tracked in Algolia:
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
- AnalyticsMutationProductSummaryViewEvent => ViewedObjectIDs
|
|
46
|
+
- AnalyticsMutationProductSummaryClickEvent => ClickedObjectIDsAfterSearch / ClickedObjectIDs
|
|
47
|
+
- AnalyticsMutationProductAddToCartEvent => AddedToCartObjectIDsAfterSearch / AddedToCartObjectIDs
|
|
48
|
+
- AnalyticsMutationPurchaseEvent => PurchasedObjectIDs
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
The `AfterSearch` variants are (with the exception of purchase) preferred by the provider in the cases where Algolia is the source of the events. For search or recommendation this would typically be the case, but not necesarily for users arriving on a PDP as a direct target from a search or a link.
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
Note that we do not map `PurchasedObjectIDsAfterSearch` as it would require us to persist the search query ID that lead to the add-to-cart occuring on the cart items. This currently seems like an excess burden to impose on the cart interface.
|
|
53
|
+
|
|
54
|
+
The `ConvertedObjectIDs` and `ConvertedObjectIDsAfterSearch` are not mapped as they seem superfluous by all accounts in a product-purchase based flow. They could likely be used for other types of conversions in a more general setup, such as a customer finishing reading an article.
|
|
55
|
+
|
|
56
|
+
Finally the events that are related to filtering are not mapped, as they are by all accounts deprecated and no longer influence any of the recommendation or personalization features.
|
package/core/initialize.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AlgoliaProductSearchProvider } from "../providers/product-search.provider.js";
|
|
2
2
|
import { AlgoliaAnalyticsProvider } from "../providers/analytics.provider.js";
|
|
3
3
|
function withAlgoliaCapabilities(configuration, capabilities) {
|
|
4
4
|
return (cache, context) => {
|
|
5
5
|
const client = {};
|
|
6
6
|
if (capabilities.productSearch) {
|
|
7
|
-
client.productSearch = new
|
|
7
|
+
client.productSearch = new AlgoliaProductSearchProvider(cache, context, configuration);
|
|
8
8
|
}
|
|
9
9
|
if (capabilities.analytics) {
|
|
10
10
|
client.analytics = new AlgoliaAnalyticsProvider(cache, context, configuration);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/provider-algolia",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@reactionary/core": "0.3.
|
|
7
|
+
"@reactionary/core": "0.3.2",
|
|
8
8
|
"algoliasearch": "^5.23.4",
|
|
9
9
|
"zod": "4.1.9"
|
|
10
10
|
},
|
|
@@ -2,13 +2,13 @@ import {
|
|
|
2
2
|
AnalyticsProvider
|
|
3
3
|
} from "@reactionary/core";
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
algoliasearch
|
|
6
6
|
} from "algoliasearch";
|
|
7
7
|
class AlgoliaAnalyticsProvider extends AnalyticsProvider {
|
|
8
8
|
constructor(cache, requestContext, config) {
|
|
9
9
|
super(cache, requestContext);
|
|
10
10
|
this.config = config;
|
|
11
|
-
this.client =
|
|
11
|
+
this.client = algoliasearch(this.config.appId, this.config.apiKey).initInsights({});
|
|
12
12
|
}
|
|
13
13
|
async processProductAddToCart(event) {
|
|
14
14
|
if (event.source && event.source.type === "search") {
|
|
@@ -21,7 +21,7 @@ class AlgoliaAnalyticsProvider extends AnalyticsProvider {
|
|
|
21
21
|
userToken: this.context.session.identityContext.personalizationKey,
|
|
22
22
|
queryID: event.source.identifier.key
|
|
23
23
|
};
|
|
24
|
-
this.client.pushEvents({
|
|
24
|
+
const response = await this.client.pushEvents({
|
|
25
25
|
events: [algoliaEvent]
|
|
26
26
|
});
|
|
27
27
|
}
|
|
@@ -37,7 +37,7 @@ class AlgoliaAnalyticsProvider extends AnalyticsProvider {
|
|
|
37
37
|
positions: [event.position],
|
|
38
38
|
queryID: event.source.identifier.key
|
|
39
39
|
};
|
|
40
|
-
this.client.pushEvents({
|
|
40
|
+
const response = await this.client.pushEvents({
|
|
41
41
|
events: [algoliaEvent]
|
|
42
42
|
});
|
|
43
43
|
}
|
|
@@ -51,7 +51,7 @@ class AlgoliaAnalyticsProvider extends AnalyticsProvider {
|
|
|
51
51
|
objectIDs: event.products.map((x) => x.key),
|
|
52
52
|
userToken: this.context.session.identityContext.personalizationKey
|
|
53
53
|
};
|
|
54
|
-
this.client.pushEvents({
|
|
54
|
+
const response = await this.client.pushEvents({
|
|
55
55
|
events: [algoliaEvent]
|
|
56
56
|
});
|
|
57
57
|
}
|
|
@@ -62,10 +62,10 @@ class AlgoliaAnalyticsProvider extends AnalyticsProvider {
|
|
|
62
62
|
eventType: "conversion",
|
|
63
63
|
eventSubtype: "purchase",
|
|
64
64
|
index: this.config.indexName,
|
|
65
|
-
objectIDs: event.order.items.map((x) => x.
|
|
65
|
+
objectIDs: event.order.items.map((x) => x.variant.sku),
|
|
66
66
|
userToken: this.context.session.identityContext.personalizationKey
|
|
67
67
|
};
|
|
68
|
-
this.client.pushEvents({
|
|
68
|
+
const response = await this.client.pushEvents({
|
|
69
69
|
events: [algoliaEvent]
|
|
70
70
|
});
|
|
71
71
|
}
|
|
@@ -23,8 +23,8 @@ import {
|
|
|
23
23
|
success
|
|
24
24
|
} from "@reactionary/core";
|
|
25
25
|
import { algoliasearch } from "algoliasearch";
|
|
26
|
-
class
|
|
27
|
-
constructor(
|
|
26
|
+
class AlgoliaProductSearchProvider extends ProductSearchProvider {
|
|
27
|
+
constructor(cache, context, config) {
|
|
28
28
|
super(cache, context);
|
|
29
29
|
this.config = config;
|
|
30
30
|
}
|
|
@@ -136,7 +136,9 @@ class AlgoliaSearchProvider extends ProductSearchProvider {
|
|
|
136
136
|
term: query.search.term,
|
|
137
137
|
facets: query.search.facets,
|
|
138
138
|
filters: query.search.filters,
|
|
139
|
-
paginationOptions: query.search.paginationOptions
|
|
139
|
+
paginationOptions: query.search.paginationOptions,
|
|
140
|
+
index: body.index || "",
|
|
141
|
+
key: body.queryID || ""
|
|
140
142
|
},
|
|
141
143
|
pageNumber: (body.page || 0) + 1,
|
|
142
144
|
pageSize: body.hitsPerPage || 0,
|
|
@@ -177,7 +179,7 @@ __decorateClass([
|
|
|
177
179
|
inputSchema: ProductSearchQueryByTermSchema,
|
|
178
180
|
outputSchema: ProductSearchResultSchema
|
|
179
181
|
})
|
|
180
|
-
],
|
|
182
|
+
], AlgoliaProductSearchProvider.prototype, "queryByTerm", 1);
|
|
181
183
|
export {
|
|
182
|
-
|
|
184
|
+
AlgoliaProductSearchProvider
|
|
183
185
|
};
|
|
@@ -11,9 +11,9 @@ interface AlgoliaNativeRecord {
|
|
|
11
11
|
name?: string;
|
|
12
12
|
variants: Array<AlgoliaNativeVariant>;
|
|
13
13
|
}
|
|
14
|
-
export declare class
|
|
14
|
+
export declare class AlgoliaProductSearchProvider extends ProductSearchProvider {
|
|
15
15
|
protected config: AlgoliaConfiguration;
|
|
16
|
-
constructor(
|
|
16
|
+
constructor(cache: Cache, context: RequestContext, config: AlgoliaConfiguration);
|
|
17
17
|
queryByTerm(payload: ProductSearchQueryByTerm): Promise<Result<ProductSearchResult>>;
|
|
18
18
|
createCategoryNavigationFilter(payload: ProductSearchQueryCreateNavigationFilter): Promise<Result<FacetValueIdentifier>>;
|
|
19
19
|
protected parseSingle(body: AlgoliaNativeRecord): {
|
|
@@ -39,6 +39,8 @@ export declare class AlgoliaSearchProvider extends ProductSearchProvider {
|
|
|
39
39
|
pageNumber: number;
|
|
40
40
|
pageSize: number;
|
|
41
41
|
};
|
|
42
|
+
index: string;
|
|
43
|
+
key: string;
|
|
42
44
|
};
|
|
43
45
|
pageNumber: number;
|
|
44
46
|
pageSize: number;
|