com.segment.analytics.TapstreamIntegrationAdapter Maven / Gradle / Ivy
package com.segment.analytics;
import android.app.Application;
import android.content.Context;
import com.tapstream.sdk.Config;
import com.tapstream.sdk.Event;
import com.tapstream.sdk.Tapstream;
import java.util.Map;
import static com.segment.analytics.Utils.isNullOrEmpty;
/**
* Tapstream is a mobile attribution tool that lets you attribute app installs to individual users
* who have visited your website, so your marketing team can know what's working.
*
* @see Tapstream
* @see Tapstream Integration
* @see Tapstream Android
* SDK
*/
class TapstreamIntegrationAdapter extends AbstractIntegrationAdapter {
boolean trackAllPages;
boolean trackCategorizedPages;
boolean trackNamedPages;
Tapstream tapstream;
Config config;
@Override void initialize(Context context, JsonMap settings)
throws InvalidConfigurationException {
trackAllPages = settings.getBoolean("trackAllPages", true);
trackCategorizedPages = settings.getBoolean("trackCategorizedPages", true);
trackNamedPages = settings.getBoolean("trackNamedPages", true);
config = new Config();
Tapstream.create((Application) context, settings.getString("accountName"),
settings.getString("sdkSecret"), config);
tapstream = Tapstream.getInstance();
}
@Override Tapstream getUnderlyingInstance() {
return tapstream;
}
@Override String key() {
return "Tapstream";
}
@Override void track(TrackPayload track) {
super.track(track);
tapstream.fireEvent(makeEvent(track.event(), track.properties()));
}
@Override void screen(ScreenPayload screen) {
super.screen(screen);
if (trackAllPages) {
tapstream.fireEvent(makeEvent("screen-" + screen.event(), screen.properties()));
} else if (trackCategorizedPages && !isNullOrEmpty(screen.category())) {
tapstream.fireEvent(makeEvent("screen-" + screen.category(), screen.properties()));
} else if (trackNamedPages && !isNullOrEmpty(screen.name())) {
tapstream.fireEvent(makeEvent("screen-" + screen.name(), screen.properties()));
}
}
private static Event makeEvent(String name, Properties properties) {
Event event = new Event(name, false);
for (Map.Entry entry : properties.entrySet()) {
event.addPair(entry.getKey(), entry.getValue());
}
return event;
}
@Override void identify(IdentifyPayload identify) {
super.identify(identify);
for (Map.Entry entry : identify.traits().entrySet()) {
config.globalEventParams.put(entry.getKey(), entry.getValue());
}
}
}