Skip to content

oliveryasuna/vaadin-logrocket-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vaadin-logrocket-integration

Integrates LogRocket with your Vaadin application.

Usage

  1. Include the dependency in your project.
<dependency>
  <groupId>org.vaadin.addons.oliveryasuna</groupId>
  <artifactId>vaadin-logrocket-integration</artifactId>
  <version>3.1.1</version>
</dependency>
  1. Set your LogRocket app ID.

Set the LOGROCKET_APP_ID environment variable to your LogRocket app ID.

Alternatively, you can set it directly in the configuration. Read more here.

  1. Add the LogRocket script to your page and initialize LogRocket.

One way to do so is by adding it to index.html:

public class LogRocketBootstrapper implements VaadinServiceInitListener, IndexHtmlRequestListener, UIInitListener {
  @Override
  public void serviceInit(final ServiceInitEvent event) {
    event.addIndexHtmlRequestListener(this);
    event.getSource().addUIInitListener(this);
  }

  @Override
  public void modifyIndexHtmlResponse(final IndexHtmlResponse response) {
    final Document document = response.getDocument();

    final Element scriptElement = document.createElement("script");
    scriptElement.attr("src", "https://cdn.lr-in-prod.com/LogRocket.min.js");
    scriptElement.attr("crossorigin", "anonymous");

    document.head().appendChild(scriptElement);
  }

  @Override
  public void uiInit(final UIInitEvent event) {
    LogRocketConfiguration.getInstance(logRocketConfiguration -> LogRocket.init(event.getUI(), ogRocketConfiguration.getAppId()));
  }
}

Alternatively, you can enable autoInit in the configuration. Read more here.

  1. Identify your users.

Use one of the identify methods in the class LogRocket to identify your users.

For example:

public void onAuthenticate(final User user) {
  LogRocket.identify(user.getId(), user.getName(), user.getEmail());
}

Configuration

To override the default configuration, create a file name vaadin-logrocket.properties in src/main/resources.

Property Description Default
autoInit Automatically adds the LogRocket script and initializes LogRocket for new UIs. false
logrocket.appId LogRocket app ID. ${LOGROCKET_APP_ID}

Alternatively, you can implement your own configuration loader by implementing the interface AddonConfigurationLoader and loading it with SPI.

License

This repository and its contents are licensed by BSD 3-Clause.

In other words, feel free to use this in your projects, but please give credits to its author(s).

Sponsoring

If you like my work and want to support it, please consider sponsoring me. It's how I make the time to code great things!

About

LogRocket integration for Vaadin Flow.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages