While using the Divi theme, custom JavaScript code such as Google Analytics, Google Adsense code, or any other JavaScript code can be added:
Globally, in the Integration Tab
Individually to any page, post, project, or Woo product
Add custom JavaScript code globally
Go to WordPress Dashboard → Divi → Theme Options
Click on the Integration Tab
Based on your code, you have the flexibility to include it either inside the page's <header> HTML tag or inside the page's <body> HTML tag:
<head> section - if you want the code to run globally on your website. Usually, this section is used for codes that should run on any page of your website
<body> section - if you want the code to run globally on your website. Usually, this section is used for Google Tracking code and/or Google Analytics code.
Add custom JavaScript code individually to a page, post, project, or Woo Product
Enabled the Visual Builder on the page, post, project, or Woo product where the custom JavaScript code should run
Insert the Code module into the layout
Place the custom JavaScript code in the Code module's Content Tab → Code
Add custom JavaScript code individually to a page, post, project, or Woo Product using the Theme Builder
From WordPress Dashboard, go to Divi → Theme Builder
Create a new template or Edit an existing template's header
In the Header's template part, add the Code module
Place the JavaScript code in the Code module's Content Tab → Code