Skip to content

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 ​

  1. Add data-lg-event with the event name to the element:

    html
    <a href="/pricing" data-lg-event="pricing.cta_clicked">See prices</a>
  2. 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>
  3. For numbers, true or false values and nested data, use data-lg-props with 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 ​

AttributeFunction
data-lg-eventThe event name
data-lg-onclick (default), submit (default on a form), view or change
data-lg-prop-*One string property
data-lg-propsA JSON object of properties
data-lg-context-*On a container: a property for each event in the container
data-lg-captureOn a form: the fields to send as properties
data-lg-identifyOn a form: the fields to send as identifiers, for example email=work_email, or off
data-lg-ignoreNo events from the element and its children
data-lg-view-thresholdFor view: the part of the element that must show. 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

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.