NAV
html

JavaScript API

Welcome to Trustisto JavaScript API documentation. You can use our API to fully integrate you website with Trustisto Marketing Automation.

If you have any problem with our API our developers are happy to help. You can send us an e-mail at it@trustisto.com

Dev Index

Initialization

To install Trustisto on you website please embed this code:

<script>
  (function(a,b,c,d,e,f,g,h,i){
    h=a.SPT={u:d},a.SP={init:function(a,b){h.ai=a;h.cb=b},
    go:function(){(h.eq=h.eq||[]).push(arguments)}},
    g=b.getElementsByTagName(c)[0],f=b.createElement(c),
    f.async=1,f.src="//js"+d+e,i=g.parentNode.insertBefore(f,g)
  })(window,document,"script",".trustisto.com","/socialproof.js");
  SP.init("WEBSITE_ID");
</script>

Make sure to replace WEBSITE_ID with your Website ID.

To start using Trustisto you need to embed our initialization snippet on your website.

You can put this code before </body> (end body tag) or you can put it inside you Tag Manager.

You can find your Website ID here: How to find website ID?

Customer ID

<script>
  SP.go('setCustomerId', "CUSTOMER_ID"; // optional
</script>

Make sure to replace CUSTOMER_ID with real Customer ID.

You can pass Customer ID if you want to identify users using you ID system.

On Page Load

Homepage

<script>
  SP.go('startPage');
</script>

This snippet should be called on the homepage of your website.

Category

<script>
  SP.go('categoryPage', {
    categoryId: "CATEGORY_ID"  // optional, but recommended
  });
</script>

This snippet should be called on the category page of your website.

<script>
  SP.go('searchPage', {
    searchQuery: "SEARCH_QUERY" // optional, but recommended
  });
</script>

This snippet should be called on the search page of your website.

Search & Category

<script>
  SP.go('categoryAndSearchPage', {
    searchQuery: "SEARCH_QUERY", // optional, but recommended, null if category page
    categoryId: "CATEGORY_ID" // optional, but recommended, null if search page
  });
</script>

In some case search & category are the same pages from the technical point of view. In that case please use this snippet.

Product Page

<script>
  SP.go('productPage', {
    productId: "PRODUCT_ID".
    product: "PRODUCT_NAME",
    link: "PRODUCT_URL",
    image: "PRODUCT_IMAGE_URL"
  });
</script>

Make sure to replace PRODUCT_* fields with real data.

This snippet should be called on the product page of your website. You need to pass product information in order to have ability to display those information later in notifications.

Basket Page

Minimal version:

<script>
  SP.go('basketPage')
</script>

Full version:

<script>
  SP.go('basketPage', [{
    productId: "PRODUCT_1_ID".
    product: "PRODUCT_1_NAME",
    link: "PRODUCT_1_URL",
    image: "PRODUCT_1_IMAGE_URL",
    quantity: PRODUCT_1_QUANTITY // integer or string
    price: PRODUCT_1_SINGLE_PRICE, // float or string
    sum: SUM // float or string, sum = quantity * price
  }, {
    productId: "PRODUCT_2_ID".
    product: "PRODUCT_2_NAME",
    link: "PRODUCT_2_URL",
    image: "PRODUCT_2_IMAGE_URL",
    quantity: PRODUCT_2_QUANTITY // integer or string
    price: PRODUCT_2_SINGLE_PRICE, // float or string
    sum: SUM // float or string, sum = quantity * price
  }]);
</script>

This snippet should be called on the basket page of your website.

You should use this version when you have been using AddToBasket Page Events. So all products have been saved in Local Cache, and we can now get them.

Thank You Page

Order information:

<script>
  SP.go('thankYouPage', {
    order: {
      id: "ORDER_ID",
      total: "ORDER_TOTAL"  // float ex. 123.00
    }
  });
</script>

Order information & delivery:

<script>
  SP.go('thankYouPage', {
    order: {
      id: "ORDER_ID",
      total: "ORDER_TOTAL"  // float ex. 123.00
    },
    client: {
      firstname: "CUSTOMER-NAME",
      city: "CUSTOMER-CITY",
      email: "CUSTOMER-EMAIL"
    }
  });
</script>

Full version:

<script>
  SP.go('thankYouPage', {
    order: {
      id: "ORDER_ID",
      total: ORDER_TOTAL  // float or string, ex. 123.00 or "123.00"
    },
    client: {
      firstname: "CUSTOMER-NAME",
      city: "CUSTOMER-CITY",
      email: "CUSTOMER-EMAIL"
    },
    basket: [{
      productId: "PRODUCT_1_ID".
      product: "PRODUCT_1_NAME",
      link: "PRODUCT_1_URL",
      image: "PRODUCT_1_IMAGE_URL",
      quantity: PRODUCT_1_QUANTITY // integer or string
      price: PRODUCT_1_SINGLE_PRICE, // float or string
      sum: SUM // float or string, sum = quantity * price
    }, {
      productId: "PRODUCT_2_ID".
      product: "PRODUCT_2_NAME",
      link: "PRODUCT_2_URL",
      image: "PRODUCT_2_IMAGE_URL",
      quantity: PRODUCT_2_QUANTITY // integer or string
      price: PRODUCT_2_SINGLE_PRICE, // float or string
      sum: SUM // float or string, sum = quantity * price
    }]
  });
</script>

Make sure to replace PRODUCT_* fields with real data.

This snippet should be called on purchase confirmation page.

Order information

You should use this version when you have been using "Add To Basket" or "Full Basket Page Snippet", and "Save Client" Page Events. So all products & delivery information have been saved in Local Cache, and we can now get them.

Order information & delivery

You should use this version when you have been using "Add To Basket" or "Full Basket Page Snippet", but NOT "Save Client" Page Events. So all products information have been saved in Local Cache, and we can now get them.

Full version

You should use this version when you have been NOT using "Add To Basket" or "Full Basket Page Snippet", and NOT using "Save Client" Page Events.

Ajax Page Reload

Some sites refresh heir pages using AJAX. URL in browser address bar is changing, but trustisto will not be notified, so all triggers related to URL will not be fired.

<script>
  SP.go('recheckUrlTriggers');
</script>

To fix this issue, you should call recheckUrlTriggers function to notify Trustisto when URL of your site changes without ful reload of a page.

On User Action

Save Client

<script>
  SP.go('saveClient', {
    firstname: "CUSTOMER-NAME",
    city: "CUSTOMER-CITY",
    email: "CUSTOMER-EMAIL"
  })
</script>

You save information about client, so they can be used later ex. when purchasing.

Add To Basket

This snippet should be called when user add some product to basket.

<script>
  SP.go('addToBasket', {
    productId: "PRODUCT_ID".
    product: "PRODUCT_NAME",
    link: "PRODUCT_URL",
    image: "PRODUCT_IMAGE_URL"
  });
</script>

Make sure to replace PRODUCT_* fields with real data.

Remove From Basket

This snippet should be called when user remove given product from basket.

<script>
  SP.go('removeFromBasket', {
    productId: "PRODUCT_ID"
  });
</script>

Make sure to replace PRODUCT_* fields with real data.

Save Basket

This snippet should be called too overwrite current user basket.

<script>
  SP.go('saveBasket', [{
    productId: "PRODUCT_1_ID".
    product: "PRODUCT_1_NAME",
    link: "PRODUCT_1_URL",
    image: "PRODUCT_1_IMAGE_URL",
    quantity: PRODUCT_1_QUANTITY // integer or string
    price: PRODUCT_1_SINGLE_PRICE, // float or string
    sum: SUM // float or string, sum = quantity * price
  }, {
    productId: "PRODUCT_2_ID".
    product: "PRODUCT_2_NAME",
    link: "PRODUCT_2_URL",
    image: "PRODUCT_2_IMAGE_URL",
    quantity: PRODUCT_2_QUANTITY // integer or string
    price: PRODUCT_2_SINGLE_PRICE, // float or string
    sum: SUM // float or string, sum = quantity * price
  }]);
</script>