Search specific term/phrase surrounded by double quotes. e.g. “deep linking”
Exclude records that contain a specific term prefixed with a minus. e.g. Android -Firebase

AMPscript for Salesforce Marketing Cloud

Overview

Salesforce Marketing Cloud allows email marketing teams to create and deploy beautiful templates to send to your customers. Branch integrates with Salesforce Marketing Cloud to enhance the user experience and attribution for your email marketing campaigns. Additionally, you can set up AMPscripts to enhance how you use Branch Links in your email templates in order to drive your users from email links to your app where they are already logged in and reduce the time to conversion.

Prerequisites

In order to use AMPscript for Universal Email, you need to have completed the following:

  1. Salesforce Marketing Cloud Integration.

Configure AMPscript

🚧

Domain Usage

Only use the app.link subdomain assigned to your app as the branch_base_url. Do not use custom subdomains or root domains.

Using Salesforce's AMPscript, add a new Content Area in Salesforce that converts web links in your email templates into Branch Links.

  1. Work with your Branch account manager to modify the following Salesforce AMPscript snippet, replaced DOMAIN-HERE with your Branch base domain (i.e. example.app.link)
%%[ VAR @deeplink, @branch_base_url SET @branch_base_url = "https://DOMAIN-HERE/3p?%243p=e_et" SET @deeplink = CONCAT(@branch_base_url, CONCAT("&%24original_url=", URLEncode(@link_to_be_wrapped, 1, 1))) ]%%
  1. In Salesforce Marketing Cloud, click on Email Studio and then Email
1338
  1. This will take you to the landing page for the email section. Click on Content in the menu bar to navigate to the Content section:
1343
  1. In the Content section, you will see a list of folders on the left side. Right click on the My Contents folder and choose Create Folder in the content builder menu:
1360
  1. Name the folder "Branch":
1830
  1. Once the folder is created, in the upper right side, click on Create button, then click Content Blocks and finally click Free Form:
2094
  1. On the Free Form screen, paste in the snippet you previously generated:
2094
  1. Click Save.

  2. In the Create Free Form window that appears, enter deeplink in the text field named Content Name. Click on Save after you enter the text:

2094
  1. You will now be back at your list of folders in the Content section with the file deeplink listed:
    You have now successfully created the deep linking AMPscript.

📘

Code Snippet

The snippet below will follow this format. The code below also has a placeholder for @branch_base_url. Replace it with yours.

%%[ VAR @deeplink, @branch_base_url SET @branch_base_url = "BASE URL FROM BRANCH" SET @deeplink = CONCAT(@branch_base_url, CONCAT("&%243p=e_et&%24original_url=", URLEncode(@link_to_be_wrapped, 1, 1))) ]%%

Add Branch Links with AMPscript

Once you have completed configuring your AMPscript, you can now convert individual links in your existing email templates into Branch Links. You will need to do this for all links in your email template that you want to convert to Branch Links.

For example, if you want to convert the link below into a Branch Link:

<a href="https://branch.io/product/1234/"> I want it! </a>

This is what the link will look like in the email template after you add the AMPscript to convert it into a Branch Link:

%%[ SET @link_to_be_wrapped = "https://branch.io/product/1234/" ContentBlockByName("My Contents\branch\deeplink") ]%%
<a href="%%=RedirectTo(@deeplink)=%%">Example link</a>

The process to convert links into Branch links using AMPscript is as follows (this flow converts the links in a separate document, and then pastes them back into your final template):

  1. Log in to Salesforce Marketing Cloud

  2. Click on Email Studio and then a sub-menu will appear. Click on Email in the dropdown menu:

868
  1. This will take you to the landing page for the Email section. Click on Content in the menu bar to navigate to the Content section:
1070
  1. Navigate to your folder containing your emails and open an existing email. Make sure the email is in HTML layout as shown below:
612
  1. Choose a link that you want to convert to a Branch deep link. Copy the text right after the href= in your email template, and paste it into a separate document. In the example, it is:

    "https://branch.io/product/1234/"

  2. Add %%[ SET @link_to_be_wrapped = before the link in your separate document. In the example, this is now:

    %%[ SET @link_to_be_wrapped = "https://branch.io/product/1234/"

  3. Add ContentBlockByName("My Contents\branch\deeplink"")]%% after the link:

    %%[ SET @link_to_be_wrapped = "https://branch.io/product/1234/"ContentBlockByName("My Contents\branch\deeplink"")]%%

  4. From the original link in your template, copy the text from and including <a until the href=. Add it to the text after %% in the last step. Please include the <a but not the href=:

    %%[ SET @link_to_be_wrapped = "https://branch.io/product/1234/" ContentBlockByName("My Contents\branch\deeplink"") ]%%<a style="_any css can be added here_"

  5. Add href="%%=RedirectTo(@deeplink)=%%" to the end:

    %%[ SET @link_to_be_wrapped = "https://branch.io/product/1234/" ContentBlockByName("My Contents\branch\deeplink"") ]%% <a style="_any css can be added here_"href="%%=RedirectTo(@deeplink)=%%"

  6. From the original link in your template, copy the end of the tag, the link text, and the closing tag (>I want it!</a> in the example) and add it to the end:

    %%[ SET @link_to_be_wrapped = "https://branch.io/product/1234/" ContentBlockByName("My Contents\branch\deeplink"") ]%% <a style="_any css can be added here_" href="%%=RedirectTo(@deeplink)=%%">I want it!</a>

  7. Copy your final result from the separate document back into your email template, replacing everything inside and including the <a></a> tags in the template.

  8. Repeat this for all your links in your email template that you want to convert to Branch deep links.

📘

Link Conversion Summary

Wherever you use <a> tags in your email templates, replace those with AMPscript to convert the web URLs into Branch links. The AMPscript references the Content Area setup earlier.

%%[SET @link_to_be_wrapped = "ADD YOUR LINK HERE" ContentBlockByName("My Contents\branch\deeplink"")]%%
<a href="%%=RedirectTo(@deeplink)=%%">Click Me</a>

For example,
Before:
<a href="https://branch.io/product/1234">Example link</a>
After:
%%[ SET @link_to_be_wrapped = "https://branch.io/product/1234" ContentBlockByName("My Contents\branch\deeplink") ]%%
<a href="%%=RedirectTo(@deeplink)=%%">Example link</a>

After you convert links into Branch links in your email templates, you must also add Salesforce's link attribute mc-deep-link="true" to your link tags to ensure the app opens in iOS:

<a mc-deep-link="true" href="https://my.app.link/3p?$3p=e_et&$original_url=..." > Open App </a>

🚧

Content Area Folder

Make sure your deeplink Content Area is in the right folder. Either change the folder to "My Contents" or change the path used by "ContentBlockByName" in the Branch script.

Free Form Content Block Examples