Using a Custom Share UI

If you have your own custom implementation of a share UI you can still benefit from the Loopy ™ social analytics platform by creating a trackable URL to be shared.

Simply use the shorten method to create a trackable URL for sharing when the user executes a share.

images/custom_ui.png

When the user elects to share using your custom UI:

final String originalUrl = "http://www.sharethis.com"; // <== The original URL you are sharing.

// Hide/Disable your UI until we create a shortlink
shareButton.setEnabled(false);

// Generate a trackable shortlink
Loopy.shorten(originalUrl, new ShareCallback() {

    @Override
    public void onResult(final Item item, final Throwable error) {

        // You can now use the "shortlink" version of your original URL

        // Set your onclick event and report the share
        shareButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                // The "channel" corresponds to the medium the user chose to share through.
                String channel = Loopy.Channel.FACEBOOK; // TODO: <== Set this

                // Don't forget to report the share!
                Loopy.reportShare(item, channel);

                // This will be the URL that is ultimately shared
                String urlToShare;

                if (error != null) {
                    // Now execute the share as you normally would
                    urlToShare = item.getShortlink();
                } else {
                    // We couldn't get a shorlink, so revert to the original URL
                    urlToShare = originalUrl;
                }

                // YOUR CODE HERE <== TODO: Implement this
            }
        });

        // Finally ensure the UI is enabled/visible
        shareButton.setEnabled(true);
    }
});