Skip to content

Commit

Permalink
changes to support visitor url
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhil-narayana-klevu committed Apr 15, 2024
1 parent 33e86af commit d3d5228
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 2 deletions.
8 changes: 8 additions & 0 deletions examples/react-klevu-ui/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ KlevuConfig.init({
recommendationsApiUrl: localStorage.getItem("demo-config")
? JSON.parse(localStorage.getItem("demo-config"))?.recommendationsApiUrl
: "",
visitorServiceUrl: localStorage.getItem("demo-config")
? JSON.parse(localStorage.getItem("demo-config"))?.visitorServiceUrl
: "",
})

export const nav = [
Expand Down Expand Up @@ -78,6 +81,11 @@ export function App() {
?.recommendationsApiUrl
: ""
}
visitorServiceUrl={
localStorage.getItem("demo-config")
? JSON.parse(localStorage.getItem("demo-config"))?.visitorServiceUrl
: ""
}
apiKey={
localStorage.getItem("demo-config")
? JSON.parse(localStorage.getItem("demo-config"))?.apiKey
Expand Down
2 changes: 2 additions & 0 deletions examples/react/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Config = {
recommendationsApiUrl: string
eventsApiV2Url: string
eventsApiV1Url: string
visitorServiceUrl: string
}

let loadedConfig: Config | undefined
Expand Down Expand Up @@ -56,6 +57,7 @@ export const config: Config = {
eventsApiV1Url: "https://stats.ksearchnet.com/analytics/",
eventsApiV2Url: "https://stats.ksearchnet.com/analytics/collect",
recommendationsApiUrl: "https://config-cdn.ksearchnet.com/recommendations/",
visitorServiceUrl: "https://visitor.service.ksearchnet.com/public/1.0",
...(loadedConfig ?? {}),
}

Expand Down
9 changes: 8 additions & 1 deletion packages/klevu-core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ type KlevuConfiguration = {
* MOI API url
*/
moiApiUrl?: string

/**
* VisitorServiceUrl for session creation
*/
visitorServiceUrl?: string
/**
*
*/
Expand Down Expand Up @@ -71,6 +74,7 @@ export class KlevuConfig {
eventsApiV1Url = "https://stats.ksearchnet.com/analytics/"
eventsApiV2Url = "https://stats.ksearchnet.com/analytics/collect"
recommendationsApiUrl = "https://config-cdn.ksearchnet.com/recommendations/"
visitorServiceUrl = "https://visitor.service.ksearchnet.com/public/1.0"
axios?: AxiosInstance
moiApiUrl = "https://moi-ai.ksearchnet.com/"
disableClickTracking = false
Expand All @@ -96,6 +100,9 @@ export class KlevuConfig {
if (config.eventsApiV2Url) {
this.eventsApiV2Url = config.eventsApiV2Url
}
if (config.visitorServiceUrl) {
this.visitorServiceUrl = config.visitorServiceUrl
}
if (config.recommendationsApiUrl) {
this.recommendationsApiUrl = config.recommendationsApiUrl
}
Expand Down
2 changes: 1 addition & 1 deletion packages/klevu-core/src/usersession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class KlevuUserSession {
}

return post<SessionApiResponse>(
`https://visitor.service.ksearchnet.com/public/1.0/${apiKey}/session`,
`${KlevuConfig.getDefault().visitorServiceUrl}/${apiKey}/session`,
payload
)
}
Expand Down
1 change: 1 addition & 0 deletions packages/klevu-ui-vue/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export const KlevuInit = /*@__PURE__*/ defineContainer<JSX.KlevuInit>('klevu-ini
'eventsV1Url',
'eventsV2Url',
'recommendationsApiUrl',
'visitorServiceUrl',
'settings',
'language',
'translation',
Expand Down
8 changes: 8 additions & 0 deletions packages/klevu-ui/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@ export namespace Components {
* Enable Data Protection
*/
"useConsent"?: boolean;
/**
* Override the default session API URL
*/
"visitorServiceUrl"?: string;
}
/**
* Lists latest searches user has made on the site
Expand Down Expand Up @@ -3059,6 +3063,10 @@ declare namespace LocalJSX {
* Enable Data Protection
*/
"useConsent"?: boolean;
/**
* Override the default session API URL
*/
"visitorServiceUrl"?: string;
}
/**
* Lists latest searches user has made on the site
Expand Down
5 changes: 5 additions & 0 deletions packages/klevu-ui/src/components/klevu-init/klevu-init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export class KlevuInit {
*/
@Prop() recommendationsApiUrl?: string

/**
* Override the default session API URL
*/
@Prop() visitorServiceUrl?: string
/**
* Global settings
*/
Expand Down Expand Up @@ -131,6 +135,7 @@ export class KlevuInit {
eventsApiV1Url: this.eventsV1Url,
eventsApiV2Url: this.eventsV2Url,
recommendationsApiUrl: this.recommendationsApiUrl,
visitorServiceUrl: this.visitorServiceUrl,
enableKlaviyoConnector: this.enableKlaviyoConnector || false,
useConsent: this.useConsent || false,
consentGiven: this.consentGiven || false,
Expand Down

0 comments on commit d3d5228

Please sign in to comment.