2.0.1 • Published 7 months ago

bily-ai-tracking v2.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

Bily Module

Bily module for customer tracking outide shopify.

Demo

React

Installation

Install bily-ai-tracking with npm

  npm install bily-ai-tracking

Usage/Examples

React

import { initTracking, getBily, BilyEventTypes, IBily } from 'bily-external-tracking';

function App() {
const [bily, setBily] = useState<IBily>();

  useEffect(() => {
    initTracking({
      shopUrl: '<STORE_URL>',
      bilyCustomHost: '<BILY_CUSTOM_HOSTNAME>',
    });
    getBily().then((bily) => {
      bily.track(BilyEventTypes.pageview, {});
      setBily(bily);
    });
  }, []);

  return (
    <div className="App">
        <button
            style={{ marginTop: 10 }}
            onClick={() => {
                bily?.track(BilyEventTypes.product_added_to_cart, {
                    products: [
                        {
                        product_id: '1235655',
                        sku: 'example',
                        name: 'Example',
                        variant: 'Example',
                        quantity: '1',
                        price: '99.99',
                        },
                    ],
                    currency: 'USD',
                    total: '99.99',
                });
            }}>
            Add To Cart Example
        </button>
        <button
            style={{ marginTop: 10 }}
            onClick={() => {
                bily?.track(BilyEventTypes.checkout_started, {
                    products: [
                        {
                        product_id: '1235655',
                        sku: 'example',
                        name: 'Example',
                        variant: 'Example',
                        quantity: '1',
                        price: '99.99',
                        },
                        {
                        product_id: '35235655',
                        sku: 'example 2',
                        name: 'Example 2',
                        variant: 'Example 2',
                        quantity: '2',
                        price: '100',
                        },
                    ],
                    currency: 'USD',
                    total: '299.99',
                    ph: '+33 3 33 33 33 3',
                    em: 'customer@example.example',
                    fn: 'Valaye',
                    ln: 'Valaye',
                    zp: '000000',
                    country: 'FR',
                    ct: 'Roissy-en-France',
                });
            }}>
            Checkout Start Example
        </button>
    </div>
  )
}

Methods Reference

Initialize tracking

initTracking
ParameterTypeDescription
shopUrlstringRequired. Your Shop url. Get the value from Bily Setting page on tracking section Here
bilyCustomHoststringRequired. Your bily custom hostname. Get the value from Bily Setting page on tracking section. Here

Get Bily tracking object

async getBily
ReturnTypeDescription
bilyPromise<IBily>Return bily object for sending tracking events

Track event

await getBily().track
ParameterTypeDescription
eventTypeBilyEventTypesRequired. The tracked event type
payloadRecord<string, BilyPayload>Required. Tracked event info

Types

BilyEventTypes

enum BilyEventTypes {
  pageview = 'pageview',
  checkout_completed = 'Order Completed',
  checkout_started = 'Checkout Started',
  payment_info_submitted = 'Payment Info Entered',
  product_added_to_cart = 'Product Added',
  product_viewed = 'Product Viewed',
  search_submitted = 'Products Searched',
  collection_viewed = 'ViewCategory',
  payment_contact_info_submitted = 'AddContactInfo',
  shipping_info_submitted = 'AddShippingInfo',
  contact_form_submitted = 'Contact',
  newsletter_registered = 'Newsletter',
  cart_viewed = 'CartViewed',
}
ReturnDescription
pageviewPage viewed
checkout_completedCheckout completed
checkout_startedCheckout Started
payment_info_submittedUser payment info submitted on checkout process
product_added_to_cartProduct added to cart
product_viewedProduct viewed
search_submittedSearch submitted
collection_viewedCatalog page viewed
search_submittedSearch submitted
payment_contact_info_submittedUser contact info submitted on checkout process
shipping_info_submittedUser shipping info submitted on checkout process
contact_form_submittedContact us form submitted
newsletter_registeredNewsletter registered
cart_viewedCart viewed

IBily

interface IBily {
  track: TrackFunction;
}

TrackFunction

type TrackFunction = (eventType: BilyEventTypes, payload: BilyPayload) => void;

BilyPayload

interface BilyPayload {
  checkoutToken?: string;
  ph?: string;
  em?: string;
  fn?: string;
  ln?: string;
  zp?: string;
  country?: string;
  ct?: string;
  total?: string;
  currency?: string;
  tax?: string;
  order_id?: string;
  products?: Array<IProduct>;
}
AttributeTypeDescription
checkoutTokenstringOptionnal Current checkout token
phstringOptionnal Customer phone number
emstringOptionnal Customer email address
fnstringOptionnal Customer first name
lnstringOptionnal Customer last name
zpstringOptionnal Customer zip code
countrystringOptionnal Customer country code
ctstringOptionnal Customer City Code
totalstringOptionnal Current purchase total amount
currencystringOptionnal Used Currency
taxstringOptionnal Purchase tax amount
order_idstringOptionnal Order id
productsIProductOptionnal List of products

IProduct

{
    sku?: string;
    variant?: string;
    product_id: string;
    name: string;
    quantity: string;
    price: string;
}
AttributeTypeDescription
skustringOptionnal Product SKU
variantstringOptionnal Product variant
product_idstringRequired Product ID
namestringRequired Product name
quantitystringRequired Product quantity
pricestringRequired Product price
1.0.2

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

2.0.1

7 months ago

2.0.0

7 months ago

1.0.3

7 months ago

1.0.1

12 months ago

1.0.0

12 months ago