Reputation: 115
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
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
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