Data attributes
Data attributes send events from your HTML without JavaScript. The SDK reads them from all elements on the page, also from elements that your page adds later.
html
<a href="/pricing" data-lg-event="pricing.cta_clicked"
data-lg-prop-plan="pro" data-lg-prop-position="hero">See pricing</a>Attributes
| Attribute | Description |
|---|---|
data-lg-event | The event name. The SDK changes it to lowercase. |
data-lg-on | The trigger: click (default), submit (default on a form), view or change |
data-lg-prop-* | One property with a string value. The part after data-lg-prop- is the key. |
data-lg-props | A JSON object of properties. Use it for numbers, booleans and nested values. |
data-lg-context-* | A property for all events from elements in this container. The nearest container has priority. |
data-lg-capture | Form fields to send as properties, for example company,role |
data-lg-identify | Form fields to send as identifiers, for example email=work_email,phone=tel. off stops the automatic identifier detection on this form. |
data-lg-ignore | The SDK sends no event from this element and its children. |
data-lg-view-threshold | For view: the part of the element that must show, from 0 to 1. 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. By default, the SDK sends it one time for each page load. |
Properties of each event
Each event from an element has the property element:
| Property | Value |
|---|---|
element.tag | The tag name, for example a or button |
element.text | The first 100 characters of the text |
element.href | The link address, if the element has one |
element.id | The id of the element, if it has one |
The automatic event element.clicked has the same element property. Refer to Automatic events.
Examples
Properties with types:
html
<button data-lg-event="demo.requested" data-lg-props='{"seats": 25, "trial": true}'>Book a demo</button>Context for a section:
html
<section data-lg-context-page_section="hero" data-lg-context-variant="b">
<a href="/signup" data-lg-event="signup.cta_clicked">Start free</a>
</section>The event signup.cta_clicked has the properties page_section and variant.
An element that shows on the page:
html
<div data-lg-event="case_study.viewed" data-lg-on="view" data-lg-view-threshold="0.5" data-lg-view-ms="1000">…</div>A form with fields to send:
html
<form data-lg-event="contact.submitted" data-lg-capture="company,role" data-lg-identify="email=work_email">
<input name="work_email" type="email">
<input name="company">
<input name="role">
</form>The SDK never sends a password, one-time code, payment, hidden or card field, also when you add it to data-lg-capture.