Live plugins for mobile - Transform customer data without redeploy

Discover how to leverage Segment's Analytics Live Plugins to seamlessly enhance data privacy by removing sensitive customer information, exemplifying an efficient and adaptable approach for businesses seeking to optimize their customer data strategies.

By Didier Garcia, Rahul Lalmalani, Doosan Baik

This is the second part in a 2 part blog series. In part 1, we explored how OwlEats uses mobile plugins within Segment to integrate location data that enriches customer targeting and incentivizes in-store pickups. You can read the full story here.

We’ll pick up where part 1 left off.

The engineers at OwlEats (our favorite food delivery startup) are already using Segment as their CDP to instrument their mobile apps and learn about customer behavior. Their goal is to trim some of PII data that they no longer need to collect. In this example, we will be removing the customer’s date of birth.

To achieve this, we will drop the property on the device using an Analytics Live Plugin. The OwlEats app won't need to send the PII (date of birth) to Segment servers or any other destination. Additionally, deploying Analytics Live Plugins does NOT require an app deployment. Once the on-device LivePlugins plugin is installed and deployed in the app, future deployments of the Analytics Live Plugins do not require the app to be published and are therefore super easy and quick to roll out.

Analytics Live Plugins

Analytics Live Plugins are JavaScript snippets that are published to your workspace, downloaded by end-users’ devices, and ready to be put into action after the next app startup. Once on the device, the Analytics Live Plugins are treated as normal on-device plugins and get access to all the same events and callbacks allowing you to transform event data via JavaScript.

How to Enable Live Plugin

There are two steps to setup the Live Plugin feature:

  1. First the OwlEats team must have the Plugin installed.

In Swift:

// Import the Live plugin
import AnalyticsLive
// Instantiate Analytics
// ...
// Add Live plugin to analytics
analytics.add(plugin: LivePlugins(fallbackFileURL: nil))

In Kotlin:

// import the Live plugin
import com.segment.analytics.plugins.livePlugin
// Instantiate analytics
// then add Live plugin
analytics.add(LivePlugins())
  1. And the OwlEats team must turn on the feature in their workspace.

The OwlEats team has to reach out to their Segment contact and request that the feature be turned on for their workspace.

Writing an Analytic Live Plugin

As mentioned earlier, Analytics Live Plugins are just JavaScript snippets that are run on devices using a built-in JavaScript Engine. All that the OwlEats team has to do is to create a LivePlugin subclass that allows them to drop the date of birth “DOB” property from all of their events:

// Define an instance of LivePlugin to handle dropping the property
class DropDateOfBirthLivePlugin extends LivePlugin {
	// The execute function is called for every event
execute(event) {
	// Drop the "dob" property.
delete event.context.dob

// Return the modified event that will eventually be uploaded.
     	return event
}
}

// Finally Add the DropDateOfBirthLivePlugin to the
// timelne as an Enrichment Plugin type.
analytics.add(new DropDateOfBirthLivePlugin(LivePluginType.Enrichment, null))

Pushing an Analytics Live Plugin to Your Workspace

Next the OwlEats team would save the contents above to a file locally (bundle.js) and use the segmentcli tool to upload the file to their workspace.

The segmentcli tool can installed using brew:

brew install segment-integrations/formulae/segmentcli

In order to use the segmentcli tool the OwlEats team must authenticate to have access to their workspace. 

  1. First, they create an AuthToken on the Segment App: Going to their workspace under app.segment.com

    1. They navigate to Settings > Workspace Settings > Access Management > Tokens

    2. Then they generate a new token by using the Create token button with Workspace Owner role

  2. Next, they authenticate using the segmentcli:

$ segmentcli auth <ProfileName> <AuthToken>

Note that profileName is a descriptive name the OwlEats team chooses to associate with their workspace like “OwlEats” or “oe-main”.

At this point the OwlEats team has authenticated and connected the segmentcli tool to their workspace and can now upload the bundle.js file saved earlier.

$ segmentcli upload <sourceId> <fileName>

Note that your “sourceID” is listed next to your “Write Key” in the segment app.

extensibility-2-graphic-1

It can take a few minutes for the Settings CDN object to be rebuilt so your Analytics Live Plugins might not be available immediately.

Conclusion

At this point, the OwlEats team has attached the bundle.js bundle to their workspace and their devices that have included the LivePlugins plugin will start to pull down the JavaScript code and add it to their timeline as if they were another regular Plugin. And again all of this happens without the delays involved in releasing a new app version which, depending on user adoption, could take weeks or more to reach the desired saturation. 

Check the source code for Analytics Live Plugins for Swift and Kotlin for more information. Learn more about creating Analytics Live Plugins here.

Test drive Segment CDP today

It’s free to connect your data sources and destinations to the Segment CDP. Use one API to collect analytics data across any platform.

Recommended articles

Loading

Want to keep updated on Segment launches, events, and updates?