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. You can 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: 'https://www.example.com/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: 'https://www.example.com/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: 'https://www.example.com/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'
        }
    }
)

Identify

Important! You should always review your planned use of Attentive's Identity features with your CSM prior to implementation.

You should call this method when you want to add an external user identifier to a specific customer's user profile. To associate the identifier correctly, you must include a phone number and/or an email address in the metadata for each method call. Shopify and Klaviyo IDs will be pulled in directly from the browser and should not be included explicitly as external identifiers. In the table below, you can find all supported fields for each event object and examples of how to call each method.

Notes:

  • Only use window.attentive.analytics.identify to set customIdentifiers. To set primary identifiers, use the __attentive_client_user_id cookie instead.
  • You should only use clientUserId and customIdentifiers to send Attentive your system-assigned unique identifiers (even when testing).
  • Sending duplicate values could lead to unintentionally bridging users together.
  • Don’t use customIdentifiers to send attributes (e.g., first name, last name). To send those types of attributes, use our Custom Attributes API.
  • Avoid sending null values or empty strings. If you don’t have a valid identifier, you should omit the field from the payload.
Event data Description Type Required
phone The phone number of the user string Optional
email The email address of the user string Optional
externalIdentifiers A list of ExternalIdentifier objects. See ExternalIdentifier - Objects section. array Optional

Example: identify event

window.attentive.analytics.identify(
    {
        phone: "9731235555",
        email:"user@gmail.com",
        externalIdentifiers: [
            {
                name: "custom-identifier-name",
                value: "custom-identifier-value"
            }
        ]
    }
)

Cart updated

This event is triggered when an item or set of items is added to or removed from a cart.

Only use this event type if you can send data about the items in a subscriber’s cart. This can help prevent potentially inaccurate cart abandonment messages from being sent, for example messages that include links to empty carts.

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 the Items - Objects section. string optional
cart The Cart object associated with the purchase. See the Objects - Cart section. string optional
user The User object associated with the purchase. See the Objects - User section. string optional

Example: cart updated event

analytics.cartUpdated({
  items: [
    {
      productId: "001",
      productVariantId: "001b",
      name: "sushi",
      productImage: "http://image-1-url",
      category: "food",
      price: {
        value: "20",
        currency: "USD",
      },
      quantity: 1,
    },
    {
      productId: "002",
      productVariantId: "002b",
      name: "burger",
      productImage: "http://image-2-url",
      category: "food",
      price: {
        value: "21",
        currency: "USD",
      },
      quantity: 10,
    },
  ],
  user: {
    phone: "212-111-3123",
    email: "example@example.com",
  },
  cart: {
    cartId: "cart-1",
    cartCoupon: "123",
  },
});

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
externalIdentifier - - - - identify
name The external identifier name string Required
value The external identifier value string Required

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.