Emissions visibility widget
Easily integrate emission estimates into your booking flow with Lune’s low-code Emissions Visibility widget.Pre-requisites
Complete the following setup steps before using this guide:Generate an API key and authenticate your account.
Set up Client Accounts to track emissions for your individual customers.
The Emissions Visibility widget is designed to display CO₂e (e.g. for a booking flow use-case). Emission estimates displayed through this widget will not be included in tracking or reporting for you or your customers.
1. Embed the Lune snippet
Add the following snippet to your front-end application in an appropriate location:
2. Generate a JWT token
To use the widget, you must authenticate using a JSON Web Token (JWT). This token verifies your identity and associates the emission estimate with the appropriate client account.The JWT token payload should include the account ID, which can be either your own account ID or that of the client for whom the booking flow is being displayed. The secret key for the token must be your API key, which can be generated in the Lune dashboard. The token should be generated in your backend-application as the API Key is a secret.See below for an example of generating the JWT token using Typescript/Javascript:
3. Add your HTML
To display the emission estimate in your front-end application, navigate to the sections where you want the estimate to appear. Then, add a div element with thelune-shipping-emission-estimate
class to each desired section.The lune-shipping-emission-estimate
class expects the following attributes:data-sessionToken
: The JWT token generated in the previous step.data-request
: Contains all the necessary information for calculating emissions. This data should be available on the page, make it easier to pass to the element.
Data request
Thedata-request
attribute expects a JSON object containing the necessary details for the emission estimate. It includes several required properties, which align with the properties used in Lune’s emissions calculation API request.shipment
legs
route
can be defined in one of two ways:- By distance travelled, specifying the amount and unit.
- By identifying the source and destination locations, using an address, an UN LOCODE, an airport code.
method
are:container_ship
diesel_truck
truck_articulated_34t
cargo_plane
What to do next...
Calculate emission estimates for actual shipments beyond the booking flow, using the full capabilities of the API.
Gain insights into how an existing emission estimate was calculated by using the Emissions Explanations widget.
Want to include emissions explanations directly in your Visibility widget? Simply add the attribute
data-enableExplanations="true"
to your lune-shipping-emission-estimate
div element.