Manually track events
Tracking Custom Events
Section titled Tracking Custom EventsCustom events can be tracked using CSQ.trackEvent()
.
import com.contentsquare.CSQCSQ.trackEvent("purchase_completed")
import com.contentsquare.CSQ;CSQ.trackEvent("purchase_completed");
It doesn’t matter what you call your event, there are ways in Product Analytics to cross-track events regardless of name. See our guide on combo events to learn more.
Adding Properties to Custom Events
Section titled Adding Properties to Custom EventsCustom events can be enhanced with a set of properties that will correspond to the tracked event when passed into the CSQ.trackEvent()
API call.
val properties = mapOf( "property1" to "sample value", "property2" to 10, "property3" to false)CSQ.trackEvent("custom_event_with_properties", properties)
Map<String, Object> properties = new HashMap<>();properties.put("property1", "sample value");properties.put("property2", 10);properties.put("property3", false);CSQ.trackEvent("custom_event_with_properties", properties);
Adding Properties to All Events
Section titled Adding Properties to All EventsIn some cases, you might want to add a property, or a collection of properties, to all events tracked by Product Analytics. Adding a global event property can be accomplished using CSQ.addEventProperties()
.
val globalProperties = mapOf( "property1" to "sample value", "property2" to 10, "property3" to false)CSQ.addEventProperties(globalProperties)
Map<String, Object> globalProperties = new HashMap<>();globalProperties.put("property1", "sample value");globalProperties.put("property2", 10);globalProperties.put("property3", false);CSQ.addEventProperties(globalProperties);
Properties that are added using the CSQ.addEventProperties()
API will be attached to all events tracked by Product Analytics, including any events that are automatically tracked by a CSQ autocapture SDK.
Once a property is no longer needed in the global collection, use CSQ.removeEventProperty()
can to remove properties one at a time.
CSQ.removeEventProperty("property1")
CSQ.removeEventProperty("property1");