Andre Shalan
Andre Shalan

Reputation: 115

Google analytics tracker for Vaadin

I'm using this plugin: https://vaadin.com/directory#!addon/googleanalyticstracker

in code example says to use

GoogleAnalyticsTracker tracker = new GoogleAnalyticsTracker("UA-658457-8", "vaadin.com");
mainWindow.addComponent(tracker);

but GoogleAnalyticsTracker doesn't implement interface Component, so when I try add it to view, I'm getting

ava.lang.ClassCastException: org.vaadin.googleanalytics.tracking.GoogleAnalyticsTracker cannot be cast to com.vaadin.ui.Component

Upvotes: 0

Views: 666

Answers (2)

gm7
gm7

Reputation: 11

I experienced the same error with the GoogleAnalyticsTracker not extending Component. The following code worked for me:

private void initGATracker(final String trackerId) {
   tracker = new GoogleAnalyticsTracker(trackerId, "demo.vaadin.com");

   // GoogleAnalyticsTracker is an extension add-on for UI so it is
   // initialized by calling .extend(UI)
   tracker.extend(UI.getCurrent());

   // Track all page views
   tracker.trackPageview("");
}

Upvotes: 1

Dragan Radevic
Dragan Radevic

Reputation: 801

Try this code:

GoogleAnalyticsTracker tracker = new GoogleAnalyticsTracker("UA-658457-8", "vaadin.com");
tracker.extend(myUI);
tracker.trackPageview("/samplecode/googleanalytics");

and see java doc for more details because the newest version extends AbstractJavaScriptExtension.

Upvotes: 0

Related Questions