Attentive Tag SDK

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 dataDescriptionTypeRequired
itemsA list of Items objects. See Items - Objects section.arrayRequired
userThe User object associated with the product view. See User - Objects section.objectOptional

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 dataDescriptionTypeRequired
itemsA list of Items objects. See Items - Objects section.arrayRequired
cartThe Cart object associated with the add to cart event. See Cart - Objects section.objectOptional
userThe User object associated with the add to cart event. See User - Objects section.objectOptional

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 dataDescriptionTypeRequired
itemsA list of Items objects. See Items - Objects section.arrayRequired
orderThe Order object associated with the purchase. See Order - Objects section.objectRequired
cartThe Cart object associated with the purchase. See Cart - Objects section.objectOptional
userThe User object associated with the purchase. See User - Objects section.objectOptional

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 dataDescriptionTypeRequired
phoneThe phone number of the userstringOptional
emailThe email address of the userstringOptional
externalIdentifiersA list of ExternalIdentifier objects. See ExternalIdentifier - Objects section.arrayOptional

Example: identify event

window.attentive.analytics.identify(
    {
        phone: "9731235555",
        email:"[email protected]",
        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 dataDescriptionTypeRequired
itemsA list of Items objects. See the Items - Objects section.stringoptional
cartThe Cart object associated with the purchase. See the Objects - Cart section.stringoptional
userThe User object associated with the purchase. See the Objects - User section.stringoptional

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: "[email protected]",
  },
  cart: {
    cartId: "cart-1",
    cartCoupon: "123",
  },
});

Objects

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

ObjectFieldDescriptionTypeRequiredRelevant event type
items----productView, addToCart, purchase
productIdA 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.stringRequired
productVariantIdA 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.stringRequired
productImageAn image of the product. This image will be used when sending MMS text messages.stringOptional for text messages; strongly recommended for emails
nameThe name of the product. This should be in a format that could be used directly in a message.stringOptional for text messages; strongly recommended for emails
priceA Price object.objectRequired
quantityThe number of products.numberOptional
categoryThe category of the product.stringOptional
order----purchase
orderIdA unique identifier for the order.stringRequired
cart----addToCart, purchase
cartIdA unique identifier for the cart.stringOptional
cartCouponThe input value of the coupon applied to the purchase.stringOptional
price----productView, addToCart, purchase
valueThe price of the product.numberRequired
currencyThe currency used for the price in ISO 4217 format.stringRequired
user----productView, addToCart, purchase
phoneThe phone number for the user triggering the event.stringOptional
emailThe email for the user triggering the event.stringOptional
externalIdentifier----identify
nameThe external identifier namestringRequired
valueThe external identifier valuestringRequired

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.