For customers setting up Salesforce Communities, or who already have an existing Salesforce Community set up and want to deploy drift on those pages.
When visitors are logged into the Community, Drift can identify their email address and other attributes from Salesforce data to recognize them and personalize experiences. This recognition is helpful in the event the visitor creates a support case or has an issue requiring follow-up. This allows the bot to avoid asking for email as users have just submitted their email/password combination to access the Community.
From inside your Workspace, select the Builder tile.

The first thing to do is install Drift. Go to Settings Icon:

Under settings find > Advanced
Under Advanced > Find Head Markup

Click on Edit Head Markup
Copy and paste the Drift install script inside the head markup, click Save.

Salesforce will show an error indicating a Content Security Policy violation, click Ok to proceed.

Find the Security & Privacy Tab

From the dropdown under Security Level select Relaxed, this will prompt another violation.

This violation results from the relaxed security level. This relaxation allows third party scripts, but only those specified in the next steps. Click Ok on the violation to proceed.
Immediately below the Security Level settings, click on Add Trusted Site.

Name the site Drift and in the URL field enter https://js.driftt.com. Verify that this spelling of Drift includes two “t’s” as this differentiates our JavaScript URL from our homepage domain. Add a second trusted site, this time enter https://*.js.driftt.com. This second trusted URL ensures that any subdomain of https://js.driftt.com will be matched.

Click Add Site. This will display the third and final CSP related violation.

This final Communities setting will violate the global Salesforce security policies. Navigate back to the main Salesforce Setup menu to continue.
Type in “CSP” in the Salesforce Setup Quick Search bar.

From the CSP Trusted Sites page, click New Trusted Site. Name the Trusted Site with the same name from the previous step in the Community Builder, e.g. “Drift”.
Add two Trusted Site URLs, enter https://js.driftt.com and https://*.js.driftt.com as in the previous steps.

Make sure the site is Active and available for all Context and Directives. Click Save.

Find your Builder setting screen again from within the Community Workspace. Scroll down to Site Cookie Usage and make sure it is allowed to support Drift functionality.

In the upper right hand corner of the Builder, click on Publish.

Copy the URL that comes up for this box, then click Publish.

This is the URL to your Community which now has Drift installed. At this step, Drift will function in a similar fashion to your public website where it will need email identity before recognizing the visitor.
You will want to check within Drift to make sure your Playbook Targeting includes the URLs related to your Salesforce Community. In this example, we created the test community at https://testdrift-developer-edition.na162.force(dot)com. An example of playbook targeting for this community might be “URL host is testdrift-developer-edition.na162.force.com”

At this step you can test Drift within Salesforce communities and begin building experiences for visitors once they are logged-in. Primary targeting will be by URL, but subsequent steps will allow Drift to use Salesforce identity to greet visitors and personalize their experience within Communities.
Identifying Visitors Using Salesforce Data
While you are editing your playbooks, add personalization tags to our greetings to verify later that the personalization is effective once we implement Salesforce data capture.

Add Identity Information to the Page
Salesforce does not automatically expose any identity information in their data layer.
Open Developer Console inside your SF Dev account > Settings > Developer Console

The Salesforce Text Editor will open, click File > New > Visual Force Page
Give your new page a name that will be easily recognizable as related to Drift; in this case we use simply test

Delete what is in the editor and replace it with the following Apex script (make sure “ “ are not slanted after pasting script).
<apex:page contentType="application/json">
{
"id": "{!$User.ContactId}",
"email": "{!$User.Email}",
"firstName": "{!$User.FirstName}",
"lastName": "{!$User.LastName}",
"title": "{!$User.Title}",
"username": "{!$User.Username}",
"email": "{!$User.Email}",
"company": "{!$User.CompanyName}"
}
</apex:page>
Once pasted into the developer console, the script should look like this:

From the menu select File > Save, then select Preview

This will show the apex script pulling in identification information based on the user who is currently logged in; this will include Customers logged in through Communities, as well as Employees accessing Communities through the web.

(Apex Resource https://help.salesforce.com/s/articleView?id=sf.code_about.htm&type=5)
From the Setup menu find the Visualforce Page you just created and ensure it is available to Experience Builder pages.

Go back to Community Builder > Settings > Advanced > Edit Head Markup then paste in this updated snippet below your default Drift JavaScript code. Remember to ensure your Drift widget ID and Visualforce Page name are updated in the areas highlighted in red. This method will also apply a page anchor “#hello” to your URL which can be customized.

Clear cookies on your browser then refresh your Community login page and authenticate through your portal. Your Drift chat bot should now greet you with the personalized greeting we created earlier, pulling in the first name from the user data being exposed in the community page through the custom Visualforce page we created.