Add deep links to your Unity mobile apps for better user experience

Adding deep links within your Unity project is a simple way to drive users directly to specific content in a mobile app – no navigation required. That content becomes easily shareable and more interactive, bringing new users, guiding existing users to new content, and more.

A deep link in a mobile app is a URL that brings a user directly to a specific in-app location. For example, deep links in a music app allow friends to share their favorite playlists, which automatically open in the music app. Embedded in search results, a deep link can take users directly to rich content in a particular app, rather than sending them to a website where they might have to enter search details again.

In addition to taking users directly to the content they’re looking for, deep links give developers the ability to add logic to the link. For example, you can drive engagement in your game by letting users share rewards or gifts via a deep link URL in SMS (or another messaging system) or allow users to jump from one game to specific content in another game, creating seamless user experiences between them. This increases user engagement and reduces friction in your mobile apps.

We introduced deep link support in Unity 2019.2 and it’s available for Android, iOS, and Universal Windows Platform (UWP). This blog post explains how you can get up and running with deep links in your Unity app.

Setting up deep links

In essence, deep linking allows you to launch, and pass parameters to, your application via a single link. You can then direct users to a specific area in your application from various sources like a web page or an SMS text message. 

To start, Unity calls the Application.deepLinkActivated event when an application is activated from a deep link URL. To process deep links in this scenario, you can:

For example, you can attach the code below to a “deep link manager” GameObject in your startup Scene.

public class ProcessDeepLinkMngr : MonoBehaviour { public static ProcessDeepLinkMngr Instance { get; private set; } public string deeplinkURL; private void Awake() { if (Instance == null) { Instance = this; Application.deepLinkActivated += onDeepLinkActivated; if (!String.IsNullOrEmpty(Application.absoluteURL)) { // Cold start and Application.absoluteURL not null so process Deep Link. onDeepLinkActivated(Application.absoluteURL); } // Initialize DeepLink Manager global variable. else deeplinkURL = “[none]”; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } } private void onDeepLinkActivated(string url) { // Update DeepLink Manager global variable, so URL can be accessed from anywhere. deeplinkURL = url; // Decode the URL to determine action. // In this example, the app expects a link formatted like this: // unitydl://mylink?scene1 string sceneName = url.Split(“?”[0])[1]; bool validScene; switch (sceneName) { case “scene1”: validScene = true; break; case “scene2”: validScene = true; break; default: validScene = false; break; } if (validScene) SceneManager.LoadScene(sceneName); } }

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

public class ProcessDeepLinkMngr : MonoBehaviour

{

public static ProcessDeepLinkMngr Instance { get; private set; }

public string deeplinkURL;

private

Continue reading

This post was originally published on this site