Singular SDK Integration for Segment

The Singular SDK is available as a plug-in for Segment. The instructions below show you how to add Singular in your Segment setup and enable the Singular SDK in your app.

Optional features include forwarding in-app events, adding the end-user's ID, and support for SKAdNetwork (on iOS devices).

Guide for Engineering Teams
Prerequisites This article assumes you already have the Segment SDK integrated in your app.

Steps for iOS Integration

1

Add Singular as a Destination

To begin, set up a Singular destination in your Segment dashboard.

To learn how to find the Singular SDK Key and Secret, see Getting Started with the Singular SDK/S2S.

mceclip0.png

2

Add the SDK to your Project

  1. Add AdServices.framework in Link Binary With Libraries and mark it as Optional (only available for devices with iOS 14.3 and higher). This is needed to support Apple Search Ads attribution.
  2. Add the Singular Segment integration pod to your app's podfile as follows:

    pod ‘Segment-Singular’
  3. Import the Singular Library in your file:

    #import "SingularIntegrationFactory.h"
3

Add Code to Initialize the Singular SDK

Obj-C Swift
SEGAnalyticsConfiguration *configuration = 
[SEGAnalyticsConfiguration configurationWithWriteKey:@”<SEGMENT_WRITE_KEY>”];

configuration use:[SingularIntegrationFactory instance]];
configuration.trackApplicationLifecycleEvents = YES;
configuration.recordScreenViews = YES;

[SEGAnalytics setupWithConfiguration:configuration];
4

[OPTIONAL] Implement Event Tracking

Use the Segment track function to have events translated and sent to Singular:

[[SEGAnalytics sharedAnalytics] track:@"simple event"];

Segment includes all the event properties as callback parameters on the Singular event, and automatically translates properties.revenue to the appropriate Singular purchase event properties.

Purchase event example:

[[SEGAnalytics sharedAnalytics] track:@"segment revenue event" properties:@{@"currency": @"USD", @"revenue":@20}];
5

[OPTIONAL] Implement User Identification

The Singular SDK can send a user ID from your app to Singular. This can be a username, email address, randomly generated string, or whichever identifier you use as a user ID.

Singular uses the user ID in user-level data exports as well as internal BI postbacks (if you configure such postbacks).

To set user identification, call the identify method:

[[SEGAnalytics sharedAnalytics] identify:@"segment custom user id"];

To unset the user ID, call the ​reset​ method:

[[SEGAnalytics sharedAnalytics] reset];
6

[OPTIONAL] Implement SKAN support

The Singular SDK can control your SKAdnetwork integration. For details on how this works, see iOS SDK: Adding SKAdNetwork Support.

To let Singular control your SKAdNetwork integration, add the following code before the initialization of the Segment SDK:

Obj-C Swift
[SingularIntegation setSKANOptions:YES
  isManualSkanConversionManagementMode: NO
  withWaitForTrackingAuthorizationWithTimeoutInterval:@0
  withConversionValueUpdatedHandler:^(NSInteger conversionValue) {
      NSLog(@"Your SKAN handler %ld",conversionValue);
  }];

 

Steps for Android Integration

1

Add Singular as a Destination

To begin, set up a Singular destination in your Segment dashboard.

To learn how to find the Singular API Key and Secret, see Getting Started with the Singular SDK/S2S.

mceclip0.png

2

Add the Plugin to Your Project

Add the Singular Segment integration dependency to your app's build.gradle file:

compile'net.singular.segment.integration:singular_segment_sdk:+'
3

Add the Required Permissions

The AndroidManifest.xml file should include the following permissions:

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="BIND_GET_INSTALL_REFERRER_SERVICE" />
4

Add Code to Initialize the Singular SDK

Use the following code to initialize the Singular SDK in your app.

Add .trackApplicationLifecycleEvents() to send app open, app updated, and app installed events to Singular.

static final String SEGMENT_WRITE_KEY = "<YOUR_KEY>";
    @Override protected void onCreate(Bundle savedInstanceState) {
        Analytics analytics = new Analytics.Builder(this , SEGMENT_WRITE_KEY)
            .use(SingularIntegration.FACTORY
            .logLevel(Analytics.LogLevel.VERBOSE)
            .recordScreenViews()
            .trackApplicationLifecycleEvents()
            .build();
        Analytics.setSingletonInstance(analytics);
    }
5

[OPTIONAL] Implement Event Tracking

Use the Segment track function to have events translated and sent to Singular:

 Analytics.with(this).track("event_name");

Segment includes all the event properties as callback parameters on the Singular event, and automatically translates properties.revenue to the appropriate Singular purchase event properties.

Purchase event example:

Analytics.with(this).track("purchase", new Properties().putRevenue(2.5).putValue("currency","USD"));
6

[OPTIONAL] Implement User Identification

The Singular SDK can send a user ID from your app to Singular. This can be a username, email address, randomly generated string, or whichever identifier you use as a user ID.

Singular uses the user ID in user-level data exports as well as internal BI postbacks (if you configure such postbacks).

To set the user ID, call the identify method:

Analytics.with(this).identify("user1234")

To unset the user ID, call the ​reset​ method:

analytics.reset();
Was this article helpful?