Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@sajari/sdk-js
Advanced tools
Changelog
2.10.8
Readme
This SDK is a lightweight JavaScript client for querying the Search.io API.
Checkout our React SDK, for a complete set of customisable UI components, and more.
You can also quickly generate search interfaces from the Search.io admin console.
npm install --save @sajari/sdk-js@next
# or with yarn
yarn add @sajari/sdk-js@next
Usage within your application:
import { Client, SearchIOAnalytics, etc... } from "@sajari/sdk-js";
const client = new Client("<account_id>", "<collection_id>");
Note that when using the SDK via a <script>
tag in a browser, all components will live under window.SajariSDK
:
<script src="https://unpkg.com/@sajari/sdk-js@^2/dist/sajarisdk.umd.production.min.js"></script>
<script>
const client = new SajariSDK.Client("<account_id>", "<collection_id>");
</script>
Create a Client
for interacting with our API, and then initialise a pipeline to be used for searching. The pipeline determines how the ranking is performed when performing a search.
If you don't have a Search.io account you can sign up.
const pipeline = new Client("<account_id>", "<collection_id>").pipeline("app");
Create a SearchIOAnalytics
instance to track events against the query id that produced a search result.
const searchio = new SearchIOAnalytics("<account_id>", "<collection_id>");
Perform a search on the specified pipeline and handle the results. Here we're searching our collection using the app
pipeline and updating the analytics instance with the current query id. The field
value you specify must be the name of a field in your schema with the Unique constraint.
const values = { q: "puppies" };
pipeline
.search(values, { type: "EVENT", field: "id" })
.then(([response, values]) => {
searchio.updateQueryId(response.queryId);
// Handle response...
})
.catch((error) => {
// Handle error...
});
Now we're going to add a basic rendering of the results to the page with integrated event tracking. This will persist the tracking event against the current query id in localStorage and send the event data to Search.io to track how users use search results and/or move through an ecommerce purchase funnel.
const values = { q: "puppies" };
pipeline
.search(values, { type: "EVENT", field: "id" })
.then(([response, values]) => {
searchio.updateQueryId(response.queryId);
response.results.forEach((r) => {
const item = document.createElement("a");
item.textContent = r.values.name;
item.href = r.values.url;
item.onclick = () => {
searchio.track("click", r.id);
};
document.body.appendChild(item);
});
})
.catch((error) => {
// Handle error...
});
When a user moves further through your purchase funnel (e.g. adding an item to their shopping cart, completing a purchase, etc) you'll want to track that also, as it will provide feedback to the ranking system. The correct query id will be preserved throughout the ecommerce funnel as long as an event with type click
was already tracked earlier.
document.querySelector(".add-to-cart").addEventListener("click", (e) => {
searchio.track("add_to_cart", e.target.id);
});
document.querySelector(".complete-purchase").addEventListener("click", (e) => {
document.querySelectorAll(".cart-item").forEach((item) => {
searchio.track("purchase", item.id);
});
});
For full documentation, see https://sajari-sdk-js.netlify.com/.
We use the MIT license
FAQs
Search.io JavaScript SDK
The npm package @sajari/sdk-js receives a total of 5,041 weekly downloads. As such, @sajari/sdk-js popularity was classified as popular.
We found that @sajari/sdk-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.