Last updated 3 minutes ago

Attentive Tag SDK

You can use Attentive’s manual event firing SDK to send events to Attentive’s analytics service. In order to use the Attentive SDK, you need to have the Attentive tag added to your site. When using the productView, addToCart, and purchase methods on the global attentive variable, you can trigger productView, addToCart, and purchase events and define the event data that is passed to Attentive for each event.

Event types

Product view

This event is triggered when a specific item is viewed. The following fields are supported for each event object. You can find examples of how to call each method in examples below the table.

Event data Description Type Required
items A list of Items objects. See Items - Objects section. array Required
user The User object associated with the product view. See User - Objects section. object Optional

Example: productView event

window.attentive.analytics.productView(
    {
        items:[
            {
                productId: '001',
                productVariantId: '001b',
                name: 'sushi',
                productImage: 'assets/images/sushi.jpg',
                category: 'food',
                price: {
                  value: '20',
                  currency: 'USD',
                },
                quantity: 1,
            }
        ], 
        user: {
            phone: '212-111-3123'
        }
    }
)

Add to cart

This event is triggered when a specific item is added to a cart. The following fields are supported for each event object. You can find examples of how to call each method in examples below the table.

Event data Description Type Required
items A list of Items objects. See Items - Objects section. array Required
cart The Cart object associated with the add to cart event. See Cart - Objects section. object Optional
user The User object associated with the add to cart event. See User - Objects section. object Optional

Example: addToCart event

window.attentive.analytics.addToCart(
    {
        items:[
            {
                productId: '001',
                productVariantId: '001b',
                name: 'sushi',
                productImage: 'assets/images/sushi.jpg',
                category: 'food',
                price: {
                  value: '20',
                  currency: 'USD',
                },
                quantity: 1,
            }
        ],
        cart: {
            cartId: 'cart-1',
            cartCoupon: '123',
        },
        user: {
            phone: '212-111-3123'
        }
    }
)

Purchase

This event is triggered when an item or set of items is purchased. The following fields are supported for each event object. You can find examples of how to call each method in examples below the table.

Event data Description Type Required
items A list of Items objects. See Items - Objects section. array Required
order The Order object associated with the purchase. See Order - Objects section. object Required
cart The Cart object associated with the purchase. See Cart - Objects section. object Optional
user The User object associated with the purchase. See User - Objects section. object Optional

Example: purchase event

window.attentive.analytics.purchase(
    {
        items:[
            {
                productId: '001',
                productVariantId: '001b',
                name: 'sushi',
                productImage: 'assets/images/sushi.jpg',
                category: 'food',
                price: {
                  value: '20',
                  currency: 'USD',
                },
                quantity: 1,
            }
        ],
        cart: {
            cartId: 'cart-1',
            cartCoupon: '123',
        },
        order: {
            orderId: 'order-1'
        }
        user: {
            phone: '212-111-3123'
        }
    }
)

Objects

The product, order, cart, price, and user objects are defined below:

Object Field Description Type Required Relevant event type
items - - - - productView, addToCart, purchase
productId A unique identifier for the product (i.e. "T-Shirt"). If you're providing a Google Shopping Feed, this should be item_group_id. If you don't have an item_group_id in your feed, use id. If you're using Shopify, this should be Shopify Product ID. string Required
productVariantId A unique identifier for the product variant (i.e. "Medium Blue T-Shirt"). If you're providing a Google Shopping Feed, this should be ID. If you're using Shopify, this should be Shopify product Variant ID. string Required
productImage An image of the product. This image will be used when sending MMS text messages. string Optional
name The name of the product. This should be in a format that could be used directly in a message. string Optional
price A Price object. object Required
quantity The number of products. number Optional
category The category of the product. string Optional
order - - - - purchase
orderId A unique identifier for the order. string Required
cart - - - - addToCart, purchase
cartId A unique identifier for the cart. string Optional
cartCoupon The input value of the coupon applied to the purchase. string Optional
price - - - - productView, addToCart, purchase
value The price of the product. number Required
currency The currency used for the price in ISO 4217 format. string Required
user - - - - productView, addToCart, purchase
phone The phone number for the user triggering the event. string Optional
email The email for the user triggering the event. string Optional

Test the event

After you add an event, complete the following steps to confirm whether your events are firing:

  1. Open Chrome browser and go to the page where an event was implemented.
  2. Right-click (or secondary-click) the page and select Inspect. The Developer Tool will appear on the right-side of the page.
  3. Click Network in the top pane.
  4. Enter events.attentive in the search field, and confirm that you see the appropriate requests sent to this domain.

Note that it is expected for these events to return as undefined in the console.