View Javadoc
1   /*
2    * Copyright (c) 2012-present Sonatype, Inc. All rights reserved.
3    *
4    * This program is licensed to you under the Apache License Version 2.0,
5    * and you may not use this file except in compliance with the Apache License Version 2.0.
6    * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7    *
8    * Unless required by applicable law or agreed to in writing,
9    * software distributed under the Apache License Version 2.0 is distributed on an
10   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12   */
13  package org.sonatype.install4j.ga;
14  
15  import com.install4j.api.context.Context;
16  
17  /**
18   * Google Analytics event tracking action.
19   *
20   * @since 1.0
21   */
22  public class TrackEventAction
23      extends GoogleAnalyticsActionSupport
24  {
25    private String category;
26  
27    private String action;
28  
29    private String label;
30  
31    private Integer value;
32  
33    public String getCategory() {
34      return category;
35    }
36  
37    public void setCategory(final String category) {
38      this.category = category;
39    }
40  
41    public String getAction() {
42      return action;
43    }
44  
45    public void setAction(final String action) {
46      this.action = action;
47    }
48  
49    public String getLabel() {
50      return label;
51    }
52  
53    public void setLabel(final String label) {
54      this.label = label;
55    }
56  
57    public Integer getValue() {
58      return value;
59    }
60  
61    public void setValue(final Integer value) {
62      this.value = value;
63    }
64  
65    @Override
66    protected boolean execute(final Context context) throws Exception {
67      if (isDisabled()) {
68        log.debug("Tracking disabled; ignoring event: {}", action);
69      }
70      else {
71        trackEvent(context);
72      }
73      return true;
74    }
75  
76    private void trackEvent(final Context context) throws Exception {
77      log.debug("Tracking event: {}", action);
78      getTracker().trackEvent(category, action, label, value);
79    }
80  }