diff options
Diffstat (limited to 'src/com/vaadin/demo/sampler/GoogleAnalytics.java')
-rw-r--r-- | src/com/vaadin/demo/sampler/GoogleAnalytics.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/com/vaadin/demo/sampler/GoogleAnalytics.java b/src/com/vaadin/demo/sampler/GoogleAnalytics.java new file mode 100644 index 0000000000..345844cee6 --- /dev/null +++ b/src/com/vaadin/demo/sampler/GoogleAnalytics.java @@ -0,0 +1,54 @@ +package com.vaadin.demo.sampler; + +import com.vaadin.terminal.PaintException; +import com.vaadin.terminal.PaintTarget; +import com.vaadin.ui.AbstractComponent; + +public class GoogleAnalytics extends AbstractComponent { + + private String trackerId; + private String pageId; + private String domainName; + + private static final String TAG = "googleanalytics"; + + public GoogleAnalytics(String trackerId) { + this.trackerId = trackerId; + } + + public GoogleAnalytics(String trackerId, String domainName) { + this(trackerId); + this.domainName = domainName; + } + + @Override + public String getTag() { + return TAG; + } + + public String getTrackerId() { + return trackerId; + } + + public String getDomainName() { + return domainName; + } + + public void trackPageview(String pageId) { + this.pageId = pageId; + requestRepaint(); + } + + @Override + public void paintContent(PaintTarget target) throws PaintException { + super.paintContent(target); + target.addAttribute("trackerid", trackerId); + if (pageId != null) { + target.addAttribute("pageid", pageId); + } + if (domainName != null) { + target.addAttribute("domain", domainName); + } + } + +} |