Use data attributes
Send events from your HTML without JavaScript. Add data-lg-* attributes to an element, and the script sends an event when a visitor uses the element.
Procedure
Add
data-lg-eventwith the event name to the element:html<a href="/pricing" data-lg-event="pricing.cta_clicked">See prices</a>Add properties with
data-lg-prop-*, one attribute for each property:html<a href="/pricing" data-lg-event="pricing.cta_clicked" data-lg-prop-plan="pro" data-lg-prop-position="hero">See prices</a>For numbers, true or false values and nested data, use
data-lg-propswith a JSON object:html<button data-lg-event="demo.requested" data-lg-props='{"seats": 25, "trial": true}'>Book a demo</button>
Result
The script sends the event on a click. It adds element with tag, text (the first 100 characters), href and id.
Attributes
| Attribute | Function |
|---|---|
data-lg-event | The event name |
data-lg-on | click (default), submit (default on a form), view or change |
data-lg-prop-* | One string property |
data-lg-props | A JSON object of properties |
data-lg-context-* | On a container: a property for each event in the container |
data-lg-capture | On a form: the fields to send as properties |
data-lg-identify | On a form: the fields to send as identifiers, for example email=work_email, or off |
data-lg-ignore | No events from the element and its children |
data-lg-view-threshold | For view: the part of the element that must show. The default is 0.5. |
data-lg-view-ms | For view: the time in milliseconds that the element must show. The default is 1000. |
data-lg-view-repeat | For view: send the event each time that the element shows |
Example: an event when a section shows
html
<section data-lg-context-page_section="case-studies">
<div data-lg-event="case_study.viewed" data-lg-on="view" data-lg-view-ms="2000">…</div>
</section>The event case_study.viewed has the property page_section with the value case-studies.