@corca-ai/data-core
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

Installation

NPM

Install @corca-ai/data-core with your package manager.

yarn add @corca-ai/data-core
npm install @corca-ai/data-core
pnpm add @corca-ai/data-core

Usage

Initialize CorcaData

Initialize the class CorcaData with your storeId and customerId. You can find storeId in the account management page.

import { CorcaData } from "@corca-ai/data-core";

const corcaData = new CorcaData({ storeId: "...", customerId: "..." });

Set Customer ID

You can set customerId to track the user's behavior.

corcaData.setCustomerId("...");

Log Collection

Page view

await corcaData.onPageView({ productId: "1234" });

Add to cart

await corcaData.onAddToCart({ productId: "1234", quantity: 1 });

Purchase

await corcaData.onPurchase({
  orderId: "20231114010101",
  amount: 29900,
  items: [
    { productId: "1234", quantity: 1 },
  ],
});

Example

import { CorcaData } from "@corca-ai/data-core";

const useCorcaData = () => {
  const [corcaData, setCorcaData] = useState<CorcaData>();
  const { me } = useFetchMe();

  useEffect(() => {
    const corcaData = new CorcaData({ storeId: "..." });
    setCorcaData(corcaData);
  }, []);

  useEffect(() => {
    if (corcaData && me) {
      corcaData.setCustomerId(me?.id);
    }
  }, [corcaData, me]);

  return corcaData;
};

export function ProductDetailPage(props: { params: { productId: string } }) {
  const corcaData = useCorcaData();

  useEffect(() => {
    if (corcaData) {
      corcaData.onPageView({ productId: props.params.productId });
    }
  }, [corcaData]);

  return (
    <div>
      ...
    </div>
  );
}

/@corca-ai/data-core/

    Package Sidebar

    Install

    npm i @corca-ai/data-core

    Weekly Downloads

    0

    Version

    0.1.2

    License

    none

    Unpacked Size

    239 kB

    Total Files

    50

    Last publish

    Collaborators

    • neverlish
    • hanch