summaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/demo/sampler/GoogleAnalytics.java
blob: ac9760592e9d15aa765fa3b35ee8937c29eb6b7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.itmill.toolkit.demo.sampler;

import com.itmill.toolkit.terminal.PaintException;
import com.itmill.toolkit.terminal.PaintTarget;
import com.itmill.toolkit.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);
        }
    }

}