Skip to content

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 ​

AttributeDescription
data-lg-eventThe event name. The SDK changes it to lowercase.
data-lg-onThe 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-propsA 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-captureForm fields to send as properties, for example company,role
data-lg-identifyForm fields to send as identifiers, for example email=work_email,phone=tel. off stops the automatic identifier detection on this form.
data-lg-ignoreThe SDK sends no event from this element and its children.
data-lg-view-thresholdFor view: the part of the element that must show, from 0 to 1. The default is 0.5.
data-lg-view-msFor view: the time in milliseconds that the element must show. The default is 1000.
data-lg-view-repeatFor 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:

PropertyValue
element.tagThe tag name, for example a or button
element.textThe first 100 characters of the text
element.hrefThe link address, if the element has one
element.idThe 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.