Search through more than a hundred articles on every aspect of User.com

Aneta Koreba
Written by Aneta Koreba

How to create product events

Learn how to send product events with our widget's API


General information

Product events are created the same way as regular events. However, there are three things you need to remember:

Firstly, you need to use a keyword "product_event".

Secondly, you must include these two attributes:

  1. product_id 
  2. event_type 

There is also one more thing that doesn't affect how you create the event, but it's closely related: we don't store information about the attributes’ values in each event. Attributes, apart from event_type, are updated with the latest value sent, which is then stored in the product’s profile (meaning that each event updates the values of all the attributes in previous events). Such an approach makes it far more efficient when you are sending tens of millions of events every month. 

However, this means you won’t be able to access or use past values of those attributes. To be able to differentiate, for example, the same shoes in different sizes, you need to create a separate product for each size.

When it comes to event_type, you can use only the types listed below:

  • add to cart
  • purchase
  • liking
  • add to observation
  • order
  • reservation
  • return
  • view
  • click
  • detail
  • add
  • remove
  • checkout
  • checkout option
  • refund
  • promo click

Remember!

Passing the name of your product in the event is not mandatory. However, if you don't include such an attribute and the product with its own ID was not created beforehand, the product will be created without a name.

Example code 

userengage('product_event', {product_id: 'the_id', event_type: 'add to cart', 'name': 'product name', 'my_attribute': 'value', 'my_attribute_2': 'value_2'})

You can also insert your product event within HTML and trigger it e.g., on click.

<a href="#" onclick="userengage('product_event', {product_id: 'the_id', event_type: 'add to cart', 'name': 'product name', 'my_attribute': 'value', 'my_attrbiute_2': 'value_2'})">CLICK ME!</a>
Categories: