-
Notifications
You must be signed in to change notification settings - Fork 4
Annotations
Welcome to a wiki page. Ganalytics is a library to simplify your work with analytics in app. Here you can find list of all currently supported annotations with their descriptions:
When we have too long named interface or category name must be named completely different from interface name (for example, they have different naming conventions), then @Category annotation comes to help use. Currently, it's very simple. When you want to specify a name of @Category for all actions, you need to mark you category-interface with this annotation and pass the desired name to it. Scope: interface, method, property(since 1.1).
When we have too long named method in interface or action name must be named completely different from method name (for example, they have different naming conventions), then @Action annotation comes to help use. Currently, it's very simple. When you want to specify a name of @Action for concrete method, you need to mark you action-method with this annotation and pass the desired name to it. Scope: method.
Annotation used when you want to add prefixes for your action in an interface. Scope: method, interface, property(since 1.1). When this annotation used on method then prefix applies only to it. When @HasPrefix used on an interface, then settings of this annotation applies to all methods of interface (expect methods that already have such annotation or methods with annotation @NoPrefix).
It has two parameters:
-
name- exactly title of prefix for using. It is not required field. If it will not be specified, then the name of the category will be applied. For example:interface SomeCategory { @HasPrefix("cat") fun someAction() }
will produce
category = "somecategory"andaction = "catsomeaction"And
interface SomeCategory { @HasPrefix fun someAction() }
will produce
category = "somecategory"andaction = "somecategorysomeaction" -
splitter- you can specify delimiter between prefix and action. For example:interface SomeCategory { @HasPrefix("cat", splitter = "-") fun someAction() }
will produce
category = "somecategory"andaction = "cat-someaction"
Note: @HasPrefix without name will use name of category as prefix.
In case when @HasPrefix used on interface (or method/property in Group Interface) for some methods you don't want to use prefix. In this case @NoPrefix can help. For example:
@HasPrefix
interface SomeCategory {
fun action1()
@NoPrefix fun action2()
}will produce two events:
-
category = "somecategory"andaction = "somecategoryaction1" -
category = "somecategory"andaction = "action2"
Scope: method, interface, property(since 1.1)
Annotation used when you want to add postfixes for your action in an interface. Scope: method, interface, property. When this annotation used on method then postfix applies only to it. When @HasPostfix used on an interface, then settings of this annotation applies to all methods of interface (expect methods that already have such annotation or methods with annotation @NoPostfix).
It has two parameters:
-
name- exactly title of postfix for using. It is required field. For example:interface SomeCategory { @HasPostfix("cat") fun someAction() }
will produce
category = "somecategory"andaction = "someactioncat"But
interface SomeCategory { @HasPostfix fun someAction() }
will not compile
-
splitter- you can specify delimiter between action and postfix. For example:interface SomeCategory { @HasPrefix("cat", splitter = "-") fun someAction() }
will produce
category = "somecategory"andaction = "someaction-cat"
Note: @HasPostfix (unlike @HasPrefix) will not use category as postfix when name is not specified (since it is required field).
In case when @HasPostfix used on interface (or method/property in Group Interface) for some methods you don't want to use postfix. In this case @NoPostfix can help. For example:
@HasPostfix("postfix")
interface AnalyticsCategory {
fun action()
@NoPostfix fun otherAction()
}will produce two events:
-
category = "category"andaction = "actionpostfix" -
category = "category"andaction = "otheraction"
Scope: method, interface, property
For determining whether an output Event should include label or value (besides category and action), the @Label annotation and set of rules must be used:
- A method of analytics interface must has a zero, one or two parameters. If there are more than two parameters, then an appropriated error will be shown.
- If method has zero arguments, then output Event will have
label = ""andvalue = 0 - If method has one argument, then it automatically be a label
- If method has two arguments, but none of them is
Number, then appropriated error will be thrown (since value must be aNumberand there is not numbers in parameter list of method, then value can not be retrieved) - If method has two arguments, and one of them is
Numberwithout@Labelannotation, then this argument will be automatically handled as value and remain one will be handled as label (whether it has@Labelannotation or not) - If method has two arguments, and both of them are
Numberwithout@Labelannotation, then first one will be a label and second one will be a value
Also custom LabelConverter can be specified. Note that it must be an kotlin object or have empty constructor. Otherwise UndeclaredThrowableException will be thrown. If LabelConverter or @Label annotation are not specified for argument, then simple toString() will be invoked.
Also there is more specific interface TypedLabelConverter, for LabelConverter that handled for some specific type of arguments. These small rules are applied to it:
- If an argument has same type or it is subtype of type specified in
TypedLabelConverter, then everything is good. - If an argument has different type than in
TypedLabelConverter, thenClassCastExceptionwill be thrown.
By default all class names and method names are converted to lower case according category and action. For example, SimpleAnalyticsInterface class name will converted to simpleanalyticsinterface category. To give some control over that process, the @Convention annotation is introduced. Scope: interface, method, property(since 1.1) Currently only predefined naming conventions are available for that annotation:
-
UPPER_SNAKE_CASE: SimpleAnalyticsInterface -> Simple_analytics_interface -
LOWER_SNAKE_CASE: SimpleAnalyticsInterface -> simple_analytics_interface -
UPPER_CAMEL_CASE: SimpleAnalyticsInterface -> SimpleAnalyticsInterface -
LOWER_CAMEL_CASE: SimpleAnalyticsInterface -> simpleAnalyticsInterface -
LOWER_CASE: SimpleAnalyticsInterface -> simpleanalyticsinterface
Also, global convention may be specified in global settings. Any custom convention may be defined here.
л