# 14.4 Create and configure a Google Cloud Function

## 14.4.1 Create your Google Cloud Function

Go to <https://console.cloud.google.com/>. Go to **Cloud Functions**.

![GCP](/files/nIL2fiBY60whZ6AlFfGa)

You'll then see this. Click **CREATE FUNCTION**.

![GCP](/files/oHoyGU8fD8U6MdKraG7L)

You'll then see this.

![GCP](/files/i3pSOiOOqaO0EnMsdux0)

Make the following choices:

* **Function name**: `--demoProfileLdap---event-forwarding`
* **Region**: select any region
* **Trigger Type**: select **HTTP**
* **Authentication**: select **Allow unauthenticated invocations**

You should now have this. Click **SAVE**.

![GCP](/files/h9JsX2CM3W3IpvlkDTfV)

Click **NEXT**.

![GCP](/files/Baqz3RLlbT5GH3YObcaq)

You'll then see this:

![GCP](/files/OwSpQiE0lojbmVke1yJe)

Make the following choices:

* **Runtime**: select **Node.js 16** (or more recent)
* **Entry point**: enter **helloAEP**

Click **ENABLE API** to enable **Cloud Build API**. You'll then see a new window. In that new window, click **ENABLE** again.

![GCP](/files/jqjqlK5VJjDLd4yS9rV6)

You'll then see this. Click **Enable**.

![GCP](/files/nE8TEYuaFQMPNhpalXAD)

Once **Cloud Build API** has been enabled, you'll see this.

![GCP](/files/4w5oxMPUN1S5GEZvV1wE)

Go back to your **Cloud Function**. In your Cloud Function Inline Editor, make sure you have the following code there:

```javascript
/**
 * Responds to any HTTP request.
 *
 * @param {!express:Request} req HTTP request context.
 * @param {!express:Response} res HTTP response context.
 */
exports.helloAEP = (req, res) => {
  let message = req.query.message || req.body.message || 'Hello World!';
  res.status(200).send(message);
};
```

Next, click **DEPLOY**.

![GCP](/files/pdqPPaVfoBPHiLvjhiFU)

You'll then see this. Your Cloud Function is now being created. This may take a couple of minutes.

![GCP](/files/1fKXmC9MgktrQKO1Kl4t)

Once your function is created and running, you'll see this. Click on your function's name to open it.

![GCP](/files/Vb5n1bdUkZLq8PE4aFrZ)

You'll then see this. Go to **TRIGGER**. You'll then see the **Trigger URL** which is what you'll use to define the endpoint in Launch Server Side.

![GCP](/files/0kQgSr5K0wV5XTfBmau1)

Copy the Trigger URL, which looks like this: **<https://europe-west1-dazzling-pillar-273812.cloudfunctions.net/vangeluw-event-forwarding>**.

In the next steps, you'll configure Adobe Experience Platform Data Collection Server to stream specific information about **Page Views** to your Google Cloud Function. Instead of just forwarding the full payload as-is, you'll only send things like **ECID**, **timestamp** and **Page Name** to your Google Cloud Function.

Here's an example of a payload that you'll need to parse to filter out the above mentioned variables:

```json
{
  "events": [
    {
      "xdm": {
        "eventType": "web.webpagedetails.pageViews",
        "web": {
          "webPageDetails": {
            "URL": "https://builder.adobedemo.com/run/vangeluw-OCUC",
            "name": "vangeluw-OCUC",
            "viewName": "vangeluw-OCUC",
            "pageViews": {
              "value": 1
            }
          },
          "webReferrer": {
            "URL": "https://builder.adobedemo.com/run/vangeluw-OCUC/equipment"
          }
        },
        "device": {
          "screenHeight": 1080,
          "screenWidth": 1920,
          "screenOrientation": "landscape"
        },
        "environment": {
          "type": "browser",
          "browserDetails": {
            "viewportWidth": 1920,
            "viewportHeight": 451
          }
        },
        "placeContext": {
          "localTime": "2022-02-23T06:51:07.140+01:00",
          "localTimezoneOffset": -60
        },
        "timestamp": "2022-02-23T05:51:07.140Z",
        "implementationDetails": {
          "name": "https://ns.adobe.com/experience/alloy/reactor",
          "version": "2.8.0+2.9.0",
          "environment": "browser"
        },
        "_experienceplatform": {
          "identification": {
            "core": {
              "ecid": "08346969856929444850590365495949561249"
            }
          },
          "demoEnvironment": {
            "brandName": "vangeluw-OCUC"
          },
          "interactionDetails": {
            "core": {
              "channel": "web"
            }
          }
        }
      },
      "query": {
        "personalization": {
          "schemas": [
            "https://ns.adobe.com/personalization/html-content-item",
            "https://ns.adobe.com/personalization/json-content-item",
            "https://ns.adobe.com/personalization/redirect-item",
            "https://ns.adobe.com/personalization/dom-action"
          ],
          "decisionScopes": [
            "eyJ4ZG06YWN0aXZpdHlJZCI6Inhjb3JlOm9mZmVyLWFjdGl2aXR5OjE0YzA1MjM4MmUxYjY1MDUiLCJ4ZG06cGxhY2VtZW50SWQiOiJ4Y29yZTpvZmZlci1wbGFjZW1lbnQ6MTRiZjA5ZGM0MTkwZWJiYSJ9",
            "__view__"
          ]
        }
      }
    }
  ],
  "query": {
    "identity": {
      "fetch": [
        "ECID"
      ]
    }
  },
  "meta": {
    "state": {
      "domain": "adobedemo.com",
      "cookiesEnabled": true,
      "entries": [
        {
          "key": "kndctr_907075E95BF479EC0A495C73_AdobeOrg_identity",
          "value": "CiYwODM0Njk2OTg1NjkyOTQ0NDg1MDU5MDM2NTQ5NTk0OTU2MTI0OVIPCPn66KfyLxgBKgRJUkwx8AH5-uin8i8="
        },
        {
          "key": "kndctr_907075E95BF479EC0A495C73_AdobeOrg_consent_check",
          "value": "1"
        },
        {
          "key": "kndctr_907075E95BF479EC0A495C73_AdobeOrg_consent",
          "value": "general=in"
        }
      ]
    }
  }
}
```

These are the fields that contain the information that needs to be parsed out:

* ECID: **events.xdm.\_experienceplatform.identification.core.ecid**
* timestamp: **timestamp**
* Page Name: **events.xdm.web.webPageDetails.name**

Let's go to Adobe Experience Platform Data Collection Server now, to configure the data elements to make that possible.

## 14.4.2 Update your Event Forwarding property: Data Elements

Go to <https://experience.adobe.com/#/data-collection/> and go to **Event Forwarding**. Search your Event Forwarding property and click it to open it.

![Adobe Experience Platform Data Collection SSF](/files/gb7k9gmyCzYFojKwXoHl)

In the left menu, go to **Data Elements**. Click **Add Data Element**.

![Adobe Experience Platform Data Collection SSF](/files/S00zlgIkfFgB68l29ovT)

You'll then see a new data element to configure.

![Adobe Experience Platform Data Collection SSF](/files/92rE8n0XrAKZG81E4IDP)

Make the following selection:

* As the **Name**, enter **customerECID**.
* As the **Extension**, select **Core**.
* As the **Data Element Type**, select **Path**.
* As the **Path**, enter `arc.event.xdm.--aepTenantId--.identification.core.ecid`. By entering this path, you'll be filtering out the field **ecid** from the event payload that is sent by the website or mobile app into the Adobe Edge.

{% hint style="info" %}
In the above and below paths, a reference is made to **arc**. **arc** stands for Adobe Resource Context and **arc** always stands for the highest available object that is available in the Server Side context. Enrichments and transformations may be added to that **arc** object using Adobe Experience Platform Data Collection Server functions.

In the above and below paths, a reference is made to **event**. **event** stands for a unique event and Adobe Experience Platform Data Collection Server will always evaluate every event individually. Sometimes, you may see a reference to **events** in the payload sent by Web SDK Client Side, but in Adobe Experience Platform Data Collection Server, every event is evaluated individually.
{% endhint %}

You'll now have this. Click **Save**.

![Adobe Experience Platform Data Collection SSF](/files/mmoMKmd27sVnoK93K0ZL)

Click **Add Data Element**.

![Adobe Experience Platform Data Collection SSF](/files/R0cTanaa3CcYhzeETAfu)

You'll then see a new data element to configure.

![Adobe Experience Platform Data Collection SSF](/files/92rE8n0XrAKZG81E4IDP)

Make the following selection:

* As the **Name**, enter **eventTimestamp**.
* As the **Extension**, select **Core**.
* As the **Data Element Type**, select **Path**.
* As the **Path**, enter **arc.event.xdm.timestamp**. By entering this path, you'll be filtering out the field **timestamp** from the event payload that is sent by the website or mobile app into the Adobe Edge.

You'll now have this. Click **Save**.

![Adobe Experience Platform Data Collection SSF](/files/pL1ykt41vKvnFHYOL9Sp)

Click **Add Data Element**.

![Adobe Experience Platform Data Collection SSF](/files/R0cTanaa3CcYhzeETAfu)

You'll then see a new data element to configure.

![Adobe Experience Platform Data Collection SSF](/files/92rE8n0XrAKZG81E4IDP)

Make the following selection:

* As the **Name**, enter **pageName**.
* As the **Extension**, select **Core**.
* As the **Data Element Type**, select **Path**.
* As the **Path**, enter **arc.event.xdm.web.webPageDetails.name**. By entering this path, you'll be filtering out the field **name** from the event payload that is sent by the website or mobile app into the Adobe Edge.

You'll now have this. Click **Save**.

![Adobe Experience Platform Data Collection SSF](/files/rXFgJrziEZMGQ5W03Ubx)

You now have these data elements created:

![Adobe Experience Platform Data Collection SSF](/files/XU51CLq9EkBDybdrOJDY)

## 14.4.3 Update your Event Forwarding property: Update a Rule

In the left menu, go to **Rules**. In the previous exercise, you created the rule **All Pages**. Click that rule to open it.

![Adobe Experience Platform Data Collection SSF](/files/etwiUySjVStA1JfbNnk3)

You'll then this. Click the **+** icon under **Actions** to add a new action.

![Adobe Experience Platform Data Collection SSF](/files/LC4l48Z3AmTBEiemWapx)

You'll then see this.

![Adobe Experience Platform Data Collection SSF](/files/s296ExKe5X6jf0vgZ5sd)

Make the following selection:

* Select the **Extension**: **Adobe Cloud Connector**.
* Select the **Action Type**: **Make Fetch Call**.

That should give you this **Name**: **Adobe Cloud Connector - Make Fetch Call**. You should now see this:

![Adobe Experience Platform Data Collection SSF](/files/n2TQcpkP4g3dCMyhOkAs)

Next, configure the following:

* Change the request protocol from GET to **POST**
* Enter the URL of the Google Cloud Function you created in one of the previous steps which looks like this: **<https://europe-west1-dazzling-pillar-273812.cloudfunctions.net/vangeluw-event-forwarding>**

You should now have this. Next, go to **Body**.

![Adobe Experience Platform Data Collection SSF](/files/yAouisEuboqe4YxRwZMN)

You'll then see this. Click the radio button for **JSON**.

![Adobe Experience Platform Data Collection SSF](/files/sjNXSkIBdTO7oguvTjxN)

Configure the **Body** as follows:

| KEY            | VALUE              |
| -------------- | ------------------ |
| customerECID   | {{customerECID}}   |
| pageName       | {{pageName}}       |
| eventTimestamp | {{eventTimestamp}} |

You'll then see this. Click **Keep Changes**.

![Adobe Experience Platform Data Collection SSF](/files/dY3Qf7YwG7KZgw96NPWa)

You'll then see this. Click **Save**.

![Adobe Experience Platform Data Collection SSF](/files/4IWljPpKMPGtWh1oEfVk)

You've now update your existing rule in a Adobe Experience Platform Data Collection Server property. Go to **Publishing Flow** to publish your changes. Open your Development library **Main** by clicking **Edit** as indicated.

![Adobe Experience Platform Data Collection SSF](/files/9IttP6rpVlmeVMtaw9kO)

Click the **Add All Changed Resources** button, after which you'll see your Rule and Data Element appear in this library. Next, click **Save & Build for Development**. Your changes are now being deployed.

![Adobe Experience Platform Data Collection SSF](/files/8RNr1QBAppnSeupLOvqf)

After a couple of minutes, you'll see that the deployment is done and ready to be tested.

![Adobe Experience Platform Data Collection SSF](/files/7odahg3le4dEZFSymtsr)

## 14.3.4 Test your configuration

Go to <https://builder.adobedemo.com/projects>. After logging in with your Adobe ID, you'll see this. Click your website project to open it.

![DSN](/files/2TzcSZHZ9qjjaR5vTN1T)

You can now follow the below flow to access the website. Click **Integrations**.

![DSN](/files/teXfdE2QZAn32fKLccCX)

On the **Integrations** page, you need to select the Data Collection property that was created in exercise 0.1.

![DSN](/files/mkSIShNMSfogSSMiwcBk)

You'll then see your demo website open up. Select the URL and copy it to your clipboard.

![DSN](/files/W2n2RRLhlFySgNdfxucc)

Open a new incognito browser window.

![DSN](/files/zZEhiofOQTVr8McFoUHf)

Paste the URL of your demo website, which you copied in the previous step. You'll then be asked to login using your Adobe ID.

![DSN](/files/cA7f3IDNG2RAUwUQgCT4)

Select your account type and complete the login process.

![DSN](/files/7uNFgLBN1WDiFJBdl5mo)

You'll then see your website loaded in an incognito browser window. For every demonstration, you'll need to use a fresh, incognito browser window to load your demo website URL.

![DSN](/files/A2EDjBzPVin0IdMO2kKf)

When you open up your browser Developer View, you can inspect Network requests as indicated below. When you use the filter **interact**, you'll see the network requests that are sent by Adobe Experience Platform Data Collection Client to the Adobe Edge.

![Adobe Experience Platform Data Collection Setup](/files/6i9pouHYKPxqeiKSXRxH)

Switch your view to your Google Cloud Function and go to **LOGS**. You should now have a view similar to this one, with a number of log entries being shown. Every time you see **Function execution started**, it means that incoming traffic was received in your Google Cloud Function.

![Adobe Experience Platform Data Collection Setup](/files/ee8stGHUauhRCBdGhtf4)

Let's update your function a bit to work with the incoming data, and display the information that was received from Adobe Experience Platform Data Collection Server. Go to **SOURCE** and click **EDIT**.

![Adobe Experience Platform Data Collection Setup](/files/o7jVgdYqiDfXxTWh28SN)

In the next screen, click **NEXT**.

![Adobe Experience Platform Data Collection Setup](/files/E2FhbVfrDtMF2vqABM36)

Update your code like this:

```javascript
/**
 * Responds to any HTTP request.
 *
 * @param {!express:Request} req HTTP request context.
 * @param {!express:Response} res HTTP response context.
 */
exports.helloAEP = (req, res) => {
  console.log('>>>>> Function has started. The following information was received from Event Forwarding:');
  console.log(req.body);

  let message = req.query.message || req.body.message || 'Hello World!';
  res.status(200).send(message);
};
```

You'll then have this. Click **DEPLOY**.

![Adobe Experience Platform Data Collection Setup](/files/oXl0tSYFw9KEofpUIUOt)

After a couple of minutes, your function will be deployed again. Click your function name to open it.

![Adobe Experience Platform Data Collection Setup](/files/PMclUDWKQsft9XpUiWmu)

On your demo website, navigate to a product, like for instance **DEIRDRE RELAXED-FIT CAPRI**.

![Adobe Experience Platform Data Collection Setup](/files/N2kld0IcCiLUnoewsiXa)

Switch your view to your Google Cloud Function and go to **LOGS**. You should now have a view similar to this one, with a number of log entries being shown.

For every page view on your demo website, you should now see a new log entry pop up in your Google Cloud Function's logs, which shows the received information.

![Adobe Experience Platform Data Collection Setup](/files/5uzBJCVVS6xCmrIRNLPm)

You've now successfully sent data that was collected by Adobe Experience Platform Data Collection, in real-time, to a Google Cloud Function endpoint. From there, that data can be used by any Google Cloud Platform application, such as BigQuery for storage and reporting or for Machine Learning use cases.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.adobesandbox.com/comprehensive-technical-tutorial-archive/module14/ex4.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
