Creating Short Referrer Links
Generate short, shareable referrer links that enable user-to-user attribution and track app installs from organic referrals.
Version Requirement: This functionality requires SDK version 1.0.0 or higher. Short links remain active for 30 days after creation.
Overview
What Are Short Referrer Links
Short links transform long, parameter-filled Singular Links into compact, secure URLs convenient for sharing via SMS, social media, or in-app invitations.
Create short links dynamically so users can share them with friends to invite them to download and use your app. Each short link tracks the referring user, enabling you to measure viral growth and attribute new installs to specific advocates.
Implementation Requirements
Required Components
Gather these elements before creating a short referrer link:
- Singular Link: A base tracking link that directs users to your app download. See Singular Links FAQ for setup instructions
- Dynamic Parameters: Optional custom parameters to add context to the link. View available options in Tracking Link Parameters
- Referrer Information: Name and ID of the user sharing the link to enable attribution of new installs back to the referrer
SDK Method
CreateReferrerShortLink
Generate a short referrer link with custom parameters and a callback handler for success and error states.
Method Signature:
public static void CreateReferrerShortLink(
string baseLink,
string referrerName,
string referrerId,
Dictionary<string, string> parameters,
Action<string, string> callback
)
Parameters:
- baseLink: The original Singular tracking link URL
- referrerName: Display name of the referring user
- referrerId: Unique identifier for the referring user
- parameters: Dictionary containing additional dynamic parameters (optional, pass null if none)
-
callback: Callback function with parameters
(string shortLinkURL, string error)
Usage Example
Create a short link with custom parameters and implement sharing logic in the success callback.
using UnityEngine;
using Singular;
using System.Collections.Generic;
public class ReferralManager : MonoBehaviour
{
public void ShareReferralLink()
{
// Create custom parameters for the link
Dictionary<string, string> parameters = new Dictionary<string, string>()
{
{ "channel", "sms" },
{ "campaign_id", "summer_promo_2025" },
{ "referral_type", "friend_invite" }
};
// Generate the short referrer link
SingularSDK.CreateReferrerShortLink(
"https://sample.sng.link/D52wc/cuvk?pcn=test", // Base Singular Link
"John Doe", // Referrer name
"user_12345", // Referrer ID
parameters, // Custom parameters
OnShortLinkCreated // Callback
);
}
// Callback method that receives the short link URL or error
private void OnShortLinkCreated(string shortLinkURL, string error)
{
if (!string.IsNullOrEmpty(shortLinkURL))
{
// Success - short link was created
Debug.Log($"Generated short link: {shortLinkURL}");
// Share the link using your preferred sharing method
ShareLink(shortLinkURL);
}
else if (!string.IsNullOrEmpty(error))
{
// Error occurred during link creation
Debug.LogError($"Error creating short link: {error}");
// Handle error - retry or show user feedback
ShowErrorMessage("Failed to create share link. Please try again.");
}
}
private void ShareLink(string shortLinkURL)
{
// Example: Use Unity's native share functionality
string shareMessage = $"Join me on this awesome app! {shortLinkURL}";
#if UNITY_ANDROID
ShareOnAndroid(shareMessage);
#elif UNITY_IOS
ShareOnIOS(shareMessage);
#else
// Fallback: Copy to clipboard
GUIUtility.systemCopyBuffer = shortLinkURL;
Debug.Log("Link copied to clipboard");
#endif
}
#if UNITY_ANDROID
private void ShareOnAndroid(string message)
{
using (AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent"))
using (AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent"))
{
intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
intentObject.Call<AndroidJavaObject>("setType", "text/plain");
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), message);
using (AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
using (AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity"))
{
AndroidJavaObject chooser = intentClass.CallStatic<AndroidJavaObject>(
"createChooser", intentObject, "Share via"
);
currentActivity.Call("startActivity", chooser);
}
}
}
#endif
#if UNITY_IOS
private void ShareOnIOS(string message)
{
// iOS native sharing implementation
// You can use a plugin like NativeShare or implement UIActivityViewController
Debug.Log($"Sharing on iOS: {message}");
}
#endif
private void ShowErrorMessage(string message)
{
// Your UI error display logic
Debug.LogWarning(message);
}
}
Implementation Best Practices
Error Handling
Implement robust error handling in the callback to manage network failures, invalid parameters, or server issues.
- Retry Logic: Implement exponential backoff for transient network errors
- User Feedback: Display clear error messages when link creation fails
- Fallback Option: Provide alternative sharing methods (e.g., share the full Singular Link if short link creation fails)
-
Validation: Verify parameters before calling
CreateReferrerShortLinkto catch issues early
Tracking and Analytics
Leverage referrer information to build viral loops and measure organic growth.
Best Practice: Use consistent referrer IDs that match your internal user identification system. This enables you to:
- Attribute new installs to specific referring users
- Reward users for successful referrals
- Track viral coefficient and K-factor metrics
- Identify your most valuable brand advocates
Link Expiration
Plan for the 30-day link lifecycle in your sharing strategy.
Important: Short links expire after 30 days. For long-term campaigns or persistent share features, generate new short links periodically or use the full Singular Link as a fallback.
Common Use Cases
In-App Referral Programs
Enable users to invite friends directly from your app with personalized referral links.
- Reward System: Track referrals and reward users for successful friend signups
- Social Sharing: Integrate with platform-native share sheets for SMS, WhatsApp, email, and social media
- Personal Invites: Include referrer name in the shared message for personalization
User-Generated Content
Create shareable links when users generate content they want to share with others.
- Content Attribution: Track which content drives the most app installs
- Creator Recognition: Attribute new users to content creators for gamification
- Campaign Tagging: Add dynamic parameters based on content type or category
Event Invitations
Generate unique links for event invitations that track which attendees bring new users.
- Event Context: Include event ID and details in link parameters
- Attendee Tracking: Measure viral spread from event to event
- Network Effects: Identify events with the highest conversion rates