Integrating Custom Analytics

App Embed

Integrating Custom Analytics

The Zappar component automatically collects and transmits anonymous usage data to the ZapWork's built in analytics system, Zapalytics. You can view this aggregated data from your ZapWorks account.

In addition to this, you may like to report information to a different analytics system used by your app, e.g. Google Analytics. The Zappar component provides a mechanism that allows you to forward relevant events to your own system should you wish to do so.

Further to this documentation, the example project included with the Zappar embed component for Android demonstrates use of this mechanism.

Constructing the BroadcastReceiver

The Zappar component will broadcast analytics data using a LocalBroadcastManager. You can register to receive this data like this:

// The Zappar component report analytics events using the LocalBroadcastManager
mManager = LocalBroadcastManager.getInstance(ctx);

// Listen for the Zappar-specific actions
IntentFilter filter = new IntentFilter();

mReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent zapparIntent) {
        String deepLinkId = zapparIntent.getStringExtra(ZapparEmbed.EXTRA_ANALYTICS_DEEP_LINK_ID);

        switch(zapparIntent.getAction()) {
                Log.d("CustomAnalytics", "Zappar experience started: " + deepLinkId);
            case ZapparEmbed.ACTION_ANALYTICS_EXPERIENCE_END:
                Log.d("CustomAnalytics", "Zappar experience ended: " + deepLinkId);
                String eventName = zapparIntent.getStringExtra(ZapparEmbed.EXTRA_ANALYTICS_EVENT_NAME);
                Log.d("CustomAnalytics", "Zappar experience " + deepLinkId + " emitted custom event: " + eventName);
mManager.registerReceiver(mReceiver, filter);

Please note that it's important to carefully consider the lifecycle of your BroadcastReceiver. The file in the example project exposes static methods in a class to provide this functionality in a pseudo-singleton fashion.

Next Steps

Open in new window