Skip to content

How to generate Branch.io deep link with PHP

Branch is providing deep linking SDK by using it we can generate deep links for web, IOS and Android. This deep links provides seamless experience for mobile users especially.

The coolest thing, which generate smart deep links that pass and carry data through application install to facilitate and track conversions and user engagement through targeted communications. We can have different targeted landing pages based on device,..etc.

What is deep link?

A deep link is a link that takes you to specific content. Most web links are deep links.

For example

https://arjunphp.com/dompdf-library-using-codeigniter-3/ – This is a deep link, it is pointed to a particular post.
https://arjunphp.com/ – This is not a deep link. It links only to the homepage, not a particular item.

Generate deep link

Here is the php function to generate deep links with branch rest api: First an account at https://developer.branch.io/ and get your branch key.

    $branch_key = ''; // your branch key.
    $ch = curl_init('https://api.branch.io/v1/url');
    $payload = json_encode([
        'branch_key'=> $branch_key,
        'campaign' => 'newProduct',
        'data' => [
            '$desktop_url': 'https://arjunphp.com',
            '$ios_url': 'https://arjunhp.com/ios',
            '$ipad_url': 'https://arjunphp.com/ipad',
            '$android_url': 'https://arjunphp.com/android']
        ]);

    curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
    curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
    # Return response instead of printing.
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    # Send request.
    $result = curl_exec($ch);
    curl_close($ch);
    return json_decode($result);
0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments