Last active
December 1, 2021 11:19
-
-
Save sagarchauhan005/a4e9a8ba302a6fbe457eba5c318e0e52 to your computer and use it in GitHub Desktop.
Kartmax Search Integration Axios Call with Analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Building Origin Search Payload | |
let form=null; | |
form.collection = "K50qtol4isMqmdFjz6xnWCFz5oAc3s"; | |
form.query = this.$route.query.q; | |
var authOptions = { | |
method: "get", | |
url: `https://ai.kartmax.in/api/{{enter_your_app_id_here}}/search-get/v1/plp-special`, | |
headers: { | |
"Content-Type": "application/json", | |
}, | |
params: form, | |
}; | |
//Preparing requests & calculating response time | |
var start = Date.now(); | |
let tempresponse = await this.$axios(authOptions); | |
var totalTimeTaken = Date.now() - start; | |
let response = await tempresponse.data; | |
//catching response and working on it | |
if (response) { | |
// sending data to the kartmax search analytics | |
response.responseTime = totalTimeTaken | |
let searchAnalytics = { | |
queryData:response.query, | |
responseData: { | |
responseTime: response.responseTime, | |
totalHits: response.totalHits, | |
uniqueId: response.uniqueId, | |
}, | |
collection: {{enter_your_collection_id_here}}, | |
}; | |
if (response.response.success === 1) { | |
this.$axios | |
.post( | |
`https://search.kartmax.in/api/{{enter_your_app_id_here}}/search/v1/analytics-record-plp`, | |
searchAnalytics | |
) | |
.then((res) => { | |
console.log("kartmax search analytics", res.data); | |
}) | |
.catch((err) => { | |
console.log("error=== kartmax search analytics", err); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment