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

KS-20482-add_analytics_for_static_image_recommandation #620

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions packages/klevu-core/src/events/KlevuEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ export class KlevuEvents {
*
* @param recommendation Metadata of what recommendation is shown
* @param products List of all products that are shown
* @param bannerInfo Information about the static banner that is shown
* @param override Ability to override any analytical keys in low level
*/
static recommendationView({
recommendationMetadata,
products,
bannerInfo,
override = {},
}: {
recommendationMetadata: Partial<RecommendationViewEventMetaData> &
Expand All @@ -118,6 +120,7 @@ export class KlevuEvents {
>
>
>
bannerInfo?: KlevuEventV2DataStaticContent
override?: Partial<KlevuRecommendationsEventV2Data>
}) {
const data: KlevuRecommendationsEventV2Data = {
Expand All @@ -137,6 +140,7 @@ export class KlevuEvents {
spot_name: recommendationMetadata.spotName,
segment_name: recommendationMetadata.segmentName || undefined,
segment_id: recommendationMetadata.segmentKey || undefined,
static_content: bannerInfo && [bannerInfo],
items:
products &&
products.map((p, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const recommendationTypeOfRequests: KlevuTypeOfRequest[] = [
export function sendRecommendationViewEvent(
eventData?: Partial<RecommendationViewEventMetaData> &
Pick<RecommendationViewEventMetaData, "logic" | "recsKey" | "title">,
override?: Partial<KlevuRecommendationsEventV2Data>
override?: Partial<KlevuRecommendationsEventV2Data>,
isMobile?: boolean
): KlevuFetchModifer {
return {
klevuModifierId: "sendMerchandisingViewEvent",
Expand All @@ -47,19 +48,42 @@ export function sendRecommendationViewEvent(
return res
}

KlevuEvents.recommendationView({
recommendationMetadata: {
...kmcData.metadata,
},
products,
override,
})
if (kmcData.staticContent && kmcData.staticContent.length !== 0) {
const resolution = isMobile ? "mobile" : "desktop"
const image =
kmcData.staticContent[0].image.find(
(image) => image.resolution === resolution
) ?? kmcData.staticContent[0].image[0]
const bannerInfo = {
resolution: resolution as "mobile" | "desktop",
index: 1,
forgiveme marked this conversation as resolved.
Show resolved Hide resolved
banner_alt_tag: image.altTag,
banner_image_url: image.url,
content_type: "image" as const,
}

KlevuEvents.recommendationView({
recommendationMetadata: {
...kmcData.metadata,
},
bannerInfo,
})
} else {
KlevuEvents.recommendationView({
recommendationMetadata: {
...kmcData.metadata,
},
products,
override,
})
}

return res
}

if (!eventData) {
throw new Error(
"Need to provider eventData parameter for custom view events"
"Need to provide eventData parameter for custom view events"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ export async function kmcRecommendation(
params: {
kmcConfig,
},
modifiers:
kmcConfig.metadata.action === "STATIC_CONTENT" ? modifiers : undefined,
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/klevu-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/klevu-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"dependencies": {
"@floating-ui/dom": "^1.5.3",
"@klevu/core": "^5.2.0",
"@klevu/core": "file:../klevu-core",
"@stencil/core": "^4.4.0",
"axios": "^1.5.1",
"lit-html": "^2.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class KlevuRecommendations {
itemGroupId: this.itemGroupId,
...this.options,
},
sendRecommendationViewEvent()
sendRecommendationViewEvent(undefined, undefined, this.#isMobile())
)
)

Expand Down
Loading