---
title: "Integrate with Google Cloud Natural Language API"
slug: "integrate-with-google-cloud-natural-language-api"
abstract: "How to integrate Content Hub with the Google Cloud Natural Language API."
---
# Integrate with Google Cloud Natural Language API

This section describes the necessary steps to integrate with Google Cloud Natural Language API. It includes an extension of the domain model, integration of Scripts, Actions and Triggers, as well as creation of an External page component (detailed in the [Cloud development](https://doc.sitecore.com/ch/en/developers/cloud-dev/cloud-development-in-content-hub.html)).

The following approach allows to create a portable and flexible solution, e.g. if needed, it can be easily disabled on executing the import.

## Schema extension

A new entity definition **M.Content.TextAnalysis** needs to be introduced with a JSON **Content.TextAnalysis.Value** property. The **M.Content** definition is to be extended with a new **ContentToTextAnalysis** parent-to-child relation to **M.Content.TextAnalysis** entity definition of **OneToOne** cardinality. Allow navigation should be set to **true**.

## Content changes

In order to update text analysis results, it is necessary to track content changes and trigger the analysis each time.

- **Script**: Introduce a new script of type **Action**, where a check of an **M.Content.TextAnalysis** entity is performed. If any properties, that belong to member groups of **Content** content group, have been updated, a corresponding key will be added to the PropertyBag. An example of such a script can be downloaded [here](https://mss-p-003-delivery.stylelabs.cloud/api/public/content/4eb575a70fea4ca3a210d6e5ac33ab23?v=7e3baa9e). Don't forget to enable it after creation.
- **Action**: Create a new Action of type **Action script** linked to the script predefined above.
- **Trigger**: Add a new Trigger with the **Entity modification** objective and **In Process** execution type. The trigger's conditions should contain an **M.Content** entity definition. The action described above is to be selected as a **pre-commit** action.

## Text analysis

- **Script**: To perform text analysis itself, create a script of type **Action**: a file with an example can be downloaded via [the link](https://mss-p-003-delivery.stylelabs.cloud/api/public/content/9bdad3e84610495bbe9236644246634a?v=5f174d58), it covers authentication, fetching all Content properties of an entity, sending a request and saving the data from a response to an **M.Content.TextAnalysis** entity.

    > [!note]
    > For authorization, the **\_authSettings** value should be replaced with the corresponding settings from the file with a key obtained during [the account setup](https://doc.sitecore.com/ch/en/users/content-hub/set-up-a-google-cloud-account.html "Set up a Google Cloud account").

- **Action**: Add a new action of type **Action script** and linked to the script.
- **Trigger**: Introduce a new Trigger with the **Entity modification** objective and **In Background** execution type. The trigger's conditions should contain an **M.Content** entity definition. The action described above is to be selected as a **post-commit** action.

## Auto-tagging

It's possible to create/link existing tags automatically based on the response from Google Cloud Natural Language API.

- **Script**: In order to enable auto-tagging, create a script of type **Action**, an example can be downloaded [here](https://mss-p-003-delivery.stylelabs.cloud/api/public/content/9d15258142de41d0b24245f2afc2de86?v=4485164a).
- **Action**: Add a new action of type **Action script** and linked to the script.
- **Trigger**: Add a new Trigger with the **Entity modification** and **Entity creation** objective and **In Background** execution type. The trigger's conditions should contain an **M.Content.TextAnalysis** entity definition together with **Content.TextAnalysis.Value** property and value **has changed**. The action described above is to be selected as a **post-commit** action.

## UI configuration

In order to configure the UI, create a new **External component**. There are some examples of [configuration](https://mss-p-003-delivery.stylelabs.cloud/api/public/content/8eb6df8534e04d95bfb78b0355c81175?v=8b140f34), [code](https://mss-p-003-delivery.stylelabs.cloud/api/public/content/db56d006c0d0491d9e91dd672857fa1b?v=bb871949) and [template](https://mss-p-003-delivery.stylelabs.cloud/api/public/content/8ce24a14c1914fa28d9760c8c67f5579?v=dc61b134).