@perceptimagery/sprie-widget

1.2.1084 • Public • Published

@perceptimagery/sprie-widget

Version : 0.1.1017

Quick Start

Make sure you acquire apikey from Sprie and have a product registered and catalogued by Sprie beforehand.

<!-- STEP 1. Load React CDN Scripts -->
<script src="https://cdn.jsdelivr.net/npm/@perceptimagery/sprie-widget"></script>


<!-- STEP 2. Load Sprie SDK -->
<script src="https://cdn.jsdelivr.net/npm/@perceptimagery/sprie-widget"></script>


<!-- STEP 3. Intialize  -->
<script>
SprieSDK.Init({ apiKey:"xxx-xxx-xxx" });
</script>


<!-- STEP 6. Trigger -->
<button onclick="SprieSDK.Load('product-sku');"> Preview </button>

SDK Reference

Sprie SDK is built on React and is released as umd library which depends on react libs (must be loaded from external cdn). To support both react projects and vanilla JS projects, SprieSDK lib has a Loader object which has following methods to run the react SDK as native vanilla SDK.

Methods

  1. Init ({apiKey})
  2. Load (sku)
  3. Check (sku)
  4. CheckBatch (skuArray)
  5. UnmountAll ( )
  6. GetSprieLink ( sku )
  7. HideWidget ( )

Init ( {apiKey } )

SprieSDK.Init( {apiKey:'xxx-xxx-xxx'} ); Must be called only once for apikey authentication. N.B. Must not be called every time product is loaded.

Params
  1. apiKey : string - apiKey received from Sprie Cloud

Load ( sku )

SprieSDK.Load( 'your-product-sku' ); Call everytime you want to load a new asset on AR on Sprie. Only SKU should be provided.

CheckSKU ( sku )

SprieSDK.Check( 'your-product-sku' ); (optional). Can be called to check if the product is registered with Sprie or not. For bulk assets, refer to CheckBatch. Should be used after authentication is done. Response : {<sku>:<boolean>}
Response Example : {"centena-bert-stone":true}

CheckSKUBatch ( skuArray )

SprieSDK.CheckSKUBatch( ['your-product-sku', 'your-product-sku2'] ); (optional). Can be called to check if an array of product skus is registered with Sprie or not. Should be used after authentication is done. Response : [{<sku>:<boolean>]}
Response Example :

[
    { "your-product-sku":true }, // this sku exists
    { "your-product-sku2": false} // this doesn't
]

UnmountAll ( )

SprieSDK.UnmountAll( ); Removes current instance of SprieSDK from website. This action is stateless, which means, refreshing the page will re-mount it again.

GetSprieLink (sku)

SprieSDK.GetSprieLink (sku)
Fetches the share link of the product (with the product page), typically to share it via an app, or show a QR code. this link appends sprie-sku query param with the given sku which helps sprie-widget to open automatically.

HideWidget ( )

SprieSDK.HideWidget ( );
Hides the widget as well as the widget icon.

Events

All Events are based on CustomEvent or Event. You can find the respective data for particular event by standard event.detail.[field].

Auth

  1. SprieEvent:onAuthLoading ({isLoading: boolean}) - ✅
  2. SprieEvent:onAuthOk () - ✅
  3. SprieEvent:onAuthErr ({err: string}) - ✅
  4. SprieEvent:onSDKReady () - ✅
  5. SprieEvent:onSDKErr ({err: string}) - ✅

IO

  1. SprieEvent:onCameraAllowed ( ) - ✅
  2. SprieEvent:onCameraDenied ( ) - ✅
  3. SprieEvent:onCameraError ({err: string}) - ✅

Assets

  1. SprieEvent:onAssetCart ({sku: string}) - ✅
  2. SprieEvent:onAssetWishlist ({sku : string}) - ✅
  3. SprieEvent:onAssetLoading ({sku: string, isLoading: boolean}) - ✅
  4. SprieEvent:onAssetLoadOk ({sku: string}) - ✅
  5. SprieEvent:onAssetLoadErr ({sku: string, err: string}) - ✅
  6. SprieEvent:onCheckAssetSKU ({[sku]:boolean}) - ✅ . e.g. Response : {'your-product-sku':true} // if it already exists
  7. SprieEvent:onCheckAssetSKUBatch ({[sku]:boolean, ...}) - ✅ . e.g. Response : {'your-product-sku':true, 'sku-2':false}

Widget

  1. SprieEvent:onWidgetMinimised ( ) - ✅

Events Example

<script>
    SprieSDK.Init({ apiKey:"xxx-xxx-xxx" });
    document.addEventListener("SprieEvent:onAssetCart", function (e) {
        alert("Added to cart " + e.detail.sku);
    });

    document.addEventListener("SprieEvent:onCameraDenied", function (e) {
        alert("Camera Denied!");
    });

    document.addEventListener("SprieEvent:onCameraError", function (e) {
        alert("Camera Error : " + e.detail.err);
    });
</script>

Advanced Examples

Check particular SKU before rendering the preview trigger button

This code checks the sku with Sprie Network and hides/shows a preview button based on the result. The checking code can return a promise and triggers a convinient event as well (where promises are not supported). This check method must be called only after authentication is successful otherwise unauthenticated API calls will return inconsistent result.

<script>
    const sku = 'my-precious-sku'; 
    let showPreviewButton = false;
    const onAuthDone = function (){
        
        SprieSDK.CheckSKU(sku);
    }

    const onCheckSKU = function (e){
        const result = e.detail; // {'my-precious-sku':true}
        if(result && Object.keys(result)[0]===sku){
            showPreviewButton = result[sku];
        }
    }

    document.addEventListener("SprieEvent:onAuthOk", onAuthDone);
    document.addEventListener("SprieEvent:onCheckAssetSKU", onCheckSKU);

    SprieSDK.Init({ apiKey:"xxx-xxx-xxx" });
</script>

Check array of SKUs on product list page

Similar to CheckSKU method. but takes an array of skus. This method is in alpha. Expect future changes.

<script>
    const arrSku = ['my-precious-sku','my-secondary-sku']; 
    let validSkus = [];
    const onAuthDone = function (){
        SprieSDK.CheckSKUBatch(arrSku);
    }

    const onCheckSKUBatch = function (e){
        const result = e.detail; // [{ 'my-precious-sku':true, 'my-secondary-sku':false }]
        validSkus = Object.keys(result).map(x=>x).filter(x=>result[x]).map(x=>x); // validSkus=['my-precious-sku'];
    }

    document.addEventListener("SprieEvent:onAuthOk", onAuthDone);
    document.addEventListener("SprieEvent:onCheckAssetSKUBatch", onCheckSKUBatch);

    SprieSDK.Init({ apiKey:"xxx-xxx-xxx" });
</script>

Hide widget on minimise

This code hides the widget on receiving the onWidgetMinimised event callback

<script>
     document.addEventListener("SprieEvent:onWidgetMinimised", function () {
        SprieSDK.HideWidget();
     });
</script>

Customize Widget

  • offset: Set possition of the widget
    • h-offset: Move offset by setting up right side position value.
    • v-offset: Move offset by setting up buttom side position value.
  • size: Chnage height width of widget
    • height: Set height of widget
    • width: Set width of widget
    • vertex: Set the corner radius in pixel
  • actionButton :
    • enabled: Includ the button which wants to show/hide
      • share
      • fav
      • cart
      • link
      • snapshot
    • radius: Change the value of corner redius in pixel
    • position: Position of the action buttons (left/right),
    • innerPosition: Position of icon inside button (left/right/center),
    • backgroundColor: Set color of action button background,
    • hoverColor: Set color of action button hover,
    • borderColor: Set color of the action button border,
    • fontHoverColor: Set font color on hover of the action button
  • tooltip:
  • backgroundColor: Set color of tooltip background,
  • typography: Set fontfamily of tooltip ,
  • fontColor": Set font color on tooltip,
  • shadowColor": Set shadow color on tooltip,
  • borderColor": Set border color on tooltip,
  • closeButton:
  • buttonColor: Set button color on tooltip,
  • backgroundColor: Set color of close button background,
  • radius: Set border of the close button border,
  • position: Position of the action buttons (left/right),
  • header:
  • backgroundColor: Set color of header background
  • bodybackgroundColor: Set color of body background
  • title:
  • fontColor: Set font color on title,
  • typography: Set fontfamily of title,
  • shadowColor: Set shadow color of title
  • subTitle:
  • fontColor": Set font color on subtitle,
  • typography":Set fontfamily of subtitle,
  • shadowColor": Set shadow color of subtitle
  • loader:
  • backgroundcolor: Set color of the loader background
  • radius: Set border of the loader dot point border
  • variantStack:
  • position: Position of the variant Stack (center),
  • innerPosition: Position of variant Stack inside (left/right),
  • activeVariantColor": Set active variant color of selected variant
  • productStack:
  • activeProductColor: Set active product color of selected product,
  • activeProductBorder: Set active product border of selected product,
  • radius: Set border of the product stack border,
  • fontColor: Set font color on product title,
  • shadowColor: Set shadow color on product title,
  • typography: Set font fontfamily product title,
  • borderColor: Set border color on product,
  • arrowColor: Set arrow color on slider arrow
  • WidgetSize: Chnage height width of widget
  • height: Set height of widget
  • width: Set width of widget
  • vertex: Set the corner radius in pixel
  • chatHeadImage: Set the image path of the head button
  • button: Set widget button shape (round/square/default)
  • position: Set position of wideget (buttom-right/buttom-left)
  • backgroundColor: Set color of the widget button background,
  • buttonColor": Set color of the button widget button,

Sample Customize Payload

{
    "offset": {
        "h-offset": 3,
        "v-offset": 10
    },
    "size": {
        "height": "60vh",
        "width": "50vw",
        "vertex": "20px"
    },
    "actionButton": {
        "enabled": {
            "share": true,
            "fav": true,
            "cart": true,
            "link": true,
            "snapshot": true
        },
        "icons": "static",
        "radius": "100%",
        "position": "left",
        "innerPosition": "center",
        "backgroundColor": "#2d2c4c",
        "hoverColor": "#d3d3d3",
        "borderColor": "#000000",
        "fontHoverColor": "#000000"
    },
    "tooltip": {
        "backgroundColor": "#000000",
        "typography": "default",
        "fontColor": "#fff",
        "shadowColor": "#ffffff",
        "borderColor": "#000000"
    },
    "closeButton": {
        "buttonColor": "#000000",
        "backgroundColor": "#2cffa7",
        "radius": "100%",
        "position": "buttom-right"
    },
    "header": {
        "backgroundColor": "#2cffa7",
        "bodybackgroundColor": "#f9f3f1"
    },
    "title": {
        "fontColor": "#2d2c4c",
        "typography": "default",
        "shadowColor": "#f9f3f1"
    },
    "subTitle": {
        "fontColor": "#2d2c4c",
        "typography": "default",
        "shadowColor": "#f9f3f1"
    },
    "loader": {
        "backgroundcolor": "#2cffa7",
        "radius": "8px"
    },
    "VariantStack": {
        "position": "center",
        "innerPosition": "left",
        "activeVariantColor": "#000000"
    },
    "ProductStack": {
        "activeProductColor": "#e1e1e1",
        "activeProductBorder": "#00000000",
        "radius": "100%",
        "fontColor": "#2d2c4c",
        "shadowColor": "#ffffff",
        "typography": "default",
        "borderColor": "#aaa",
        "arrowColor": "#2cffa7"
    },
    "widgetSize": {
        "height": "60vh",
        "width": "50vw",
        "vertex": "20px"
    },
    "button": "default",
    "chatHeadImage": "https://sprie-jarvis-public.s3.eu-west-2.amazonaws.com/chatheadimage.png",
    "position": "bottom-right",
    "backgroundColor": "#000000",
    "buttonColor": "#000000",
     "apiVersion": "1",
    "widgetVersion": "1"
}

Test update version

https://cdn.jsdelivr.net/npm/@perceptimagery/sprie-widget

Readme

Keywords

none

Package Sidebar

Install

npm i @perceptimagery/sprie-widget

Weekly Downloads

1

Version

1.2.1084

License

UNLICENSED

Unpacked Size

1.36 MB

Total Files

11

Last publish

Collaborators

  • nilesh-percept
  • abhishek-percept