Directory

← Back

GoogleAnalyticsTracker

Track Vaadin application use with Google Analytics

Author

Contributors

Rating

Google Analytics is a JavaScript based tracking service for websites. With this widget you can track any application events using a simple API. The Vaadin 7 version also supports Navigator API for automatic reporting.

Vaadin version compatibility:

Add-on Vaadin version
1.x Vaadin 6.x
2.x Vaadin 7.x
3.x Vaadin 8.x
4.x Vaadin 10+

Notes

  • Since version 2.1.0 (Vaadin 7) Universal Analytics (analytics.js) is the default.
  • Since version 2.2.0 event and user-id tracking was added
  • Since version 2.2.0 project structure changed

Sample code

// Create a tracker for vaadin.com domain.
GoogleAnalyticsTracker tracker = new GoogleAnalyticsTracker("UA-658457-8",
        "vaadin.com");

// Add only one tracker per window.
mainWindow.addComponent(tracker);

// Track the page view
tracker.trackPageview("/samplecode/googleanalytics");
package org.vaadin.googleanalytics.tracking;

import com.vaadin.Application;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;

public class GoogleanAlyticsSampleApplication extends Application {
    private static final long serialVersionUID = 1L;

    @Override
    public void init() {
        Window mainWindow = new Window(
                "GoogleanAlyticsWidget Sample Application");

        // A meaningless Label just to add some content
        Label label = new Label("Hello Vaadin user");
        mainWindow.addComponent(label);

        // Create a tracker for vaadin.com domain.
        GoogleAnalyticsTracker tracker = new GoogleAnalyticsTracker("UA-658457-8",
                "vaadin.com");

        // Add only one tracker per window.
        mainWindow.addComponent(tracker);

        // Track the page view
        tracker.trackPageview("/samplecode/googleanalytics");

        // Assign main window
        setMainWindow(mainWindow);
    }

}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

  • Added event tracking. Special thanks to Ranil Wijeyratne.
  • User ID support by Marc Jay
  • Updated project layout to Maven Release plugin format
Released
2017-07-05
Maturity
STABLE
License
Apache License 2.0

Compatibility

Framework
Vaadin 7.1+
Vaadin 6.0+ in 1.1.2
Vaadin 8.0+ in 3.0.0
Vaadin 10+ in 4.0.1
Browser
Browser Independent
Online