public static Tracklytics init(EventSubscriber eventSubscriber) { Tracklytics tracklytics = new Tracklytics(eventSubscriber); TracklyticsAspect.subscribe(tracklytics); return tracklytics; }
@TrackEvent("transform") @TransformAttributeMap( keys = {1, 2}, values = {"finished", "accepted"} ) private void onItemSelected(@TransformAttribute("status") int position) { }
@TrackEvent("button_click") @FixedAttribute(key = "button_name", value = "Login") @Override public void onClick(View v) { } });
@Test public void fixedAttributeOnMethodScope() throws Throwable { class Foo { @TrackEvent("title") @FixedAttribute(key = "key1", value = "value") public String foo() { return "returnValue"; } } invokeMethod(Foo.class, "foo"); assertTrack() .event("title") .noFilters() .noTags() .attribute("key1", "value"); }
private void addFixedAttributes(FixedAttributes fixedAttributes, Map<String, Object> attributes) { if (fixedAttributes == null) return; FixedAttribute[] attributeList = fixedAttributes.value(); for (FixedAttribute attribute : attributeList) { attributes.put(attribute.key(), attribute.value()); if (attribute.isSuper()) { addSuperAttribute(attribute.key(), attribute.value()); } } }
public void trackEvent(String eventName) { trackEvent(new Event(eventName, null, null, null, superAttributes)); }
private void trackEvent(Event event) { eventSubscriber.onEventTracked(event); log(event); }
@TrackEvent("login") private void onLoggedIn(@TrackableAttribute User user, @Attribute("id") String id) { }
@TrackEvent("another_event") @Attribute("user_id") // This attribute will use return value as attribute value. private String userId() { return "2342"; }
@Override public void onAspectSuperAttributeRemoved(String key) { removeSuperAttribute(key); } }
@Override public void onAspectSuperAttributeAdded(String key, Object value) { addSuperAttribute(key, value); }
private void pushEvent(TrackEvent trackEvent, Map<String, Object> attributes) { if (aspectListener == null) return; aspectListener.onAspectEventTriggered(trackEvent, attributes); }
private void addSuperAttribute(String key, Object value) { if (aspectListener == null) return; aspectListener.onAspectSuperAttributeAdded(key, value); }
private void removeSuperAttribute(String key) { if (aspectListener == null) return; aspectListener.onAspectSuperAttributeRemoved(key); }
@TrackEvent("event_java") public void trackFoo() { } }
@Test public void useDefaultValueWhenThereIsNoReturnValue() throws Throwable { class Foo { @TrackEvent("title") @Attribute(value = "key1", defaultValue = "defaultValue") public void foo() { } } invokeMethod(Foo.class, "foo"); assertTrack() .event("title") .noFilters() .noTags() .attribute("key1", "defaultValue"); }
@Override public void onAspectEventTriggered(TrackEvent trackEvent, Map<String, Object> attributes) { trackEvent(new Event(trackEvent, attributes, superAttributes)); }
public void trackEvent(String eventName, Map<String, Object> attributes) { trackEvent(new Event(eventName, null, null, attributes, superAttributes)); }