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();
filter.addAction(ZapparEmbed.ACTION_ANALYTICS_EXPERIENCE_START);
filter.addAction(ZapparEmbed.ACTION_ANALYTICS_EXPERIENCE_END);
filter.addAction(ZapparEmbed.ACTION_ANALYTICS_EXPERIENCE_CUSTOM_EVENT);

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

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

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

Suggested Next Steps

zapcode branded_zapcode i