# Contact Endpoint API integration and Google Analytics

**URL:** <https://community.hubspot.com/t/contact-endpoint-api-integration-and-google-analytics/72547>\
**Category:** APIs & Integrations\
**Created:** [January 10, 2023, 2:53pm UTC](https://community.hubspot.com/t/contact-endpoint-api-integration-and-google-analytics/72547 "2023-01-10T14:53:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![06401](https://avatars.discourse-cdn.com/v4/letter/0/d07c76/32.png) [@06401](https://community.hubspot.com/u/06401)\
**Post date:** [January 10, 2023, 2:53pm UTC](https://community.hubspot.com/t/contact-endpoint-api-integration-and-google-analytics/72547/1 "2023-01-10T14:53:41Z")

</div>

Hello All,

We used to use the method of [Submit data to a form](https://legacydocs.hubspot.com/docs/methods/forms/submit_form) Endpoint to send the registartion data to Hubspot. However, we started to use [Contact data endpoint](https://developers.hubspot.com/docs/api/crm/contacts) since we need to send registartion data 2 times due to nature of our form.

Our developers says that there will be no form submission with this approach, there will be only contact creation. So I am wondering how can I see form submission in Google tag manager? Do you have suggestions?

Normally, we used to track them like below:

gtmEventCategory: “sign-up.form”,

gtmEventAction: “form.submit”,

gtmEventLabel: “verifyMailForm”

Thanks,

Sebnem

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [January 11, 2023, 5:35pm UTC](https://community.hubspot.com/t/contact-endpoint-api-integration-and-google-analytics/72547/2 "2023-01-11T17:35:30Z")

</div>

Hey, @06401 👋 Thanks for reaching out. Let’s see if we can get the conversation going — @LMeert [@Ben-M](https://community.hubspot.com/t5/user/viewprofilepage/user-id/123138) @Leonard0 do you have any insight you can share with @06401?

Thank you very much! — Jaycee

---

<div class="post-metadata">

**Author:** ![Leonard0](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/leonard0/32/64245_2.png) [@Leonard0](https://community.hubspot.com/u/Leonard0)\
**Post date:** [January 16, 2023, 9:09am UTC](https://community.hubspot.com/t/contact-endpoint-api-integration-and-google-analytics/72547/3 "2023-01-16T09:09:28Z")

</div>

Hi Sebnem,

It is not possible to directly push data to a Google Data Studio data layer from an external script that is not executed on the webpage. The Google Data Studio data layer is a JavaScript object that is only accessible within the context of the webpage where it is loaded. However, there is a workaround that you can use to send data to Data Studio from an external script.

You can use a server-side script to collect data from your external script and then send it to Data Studio using the Data Studio API. Here’s an example of a server-side script in Node.js that collects data from an external script and sends it to a Data Studio report using the Data Studio API:

```lia-code-sample
const {google} = require('googleapis');
const dataStudio = google.datastudio('v1');

const reportId = 'REPORT_ID';
const datasetId = 'DATASET_ID';

// Collect data from form submission
app.post('/form-submission', (req, res) => {
 const data = {
 category: req.body.category,
 action: req.body.action,
 label: req.body.label,
 date: new Date().toISOString()
 };

 // Authenticate with the Google API
 const auth = new google.auth.JWT(
 'your-service-account-email',
 'path/to/privatekey.pem',
 'your-private-key',
 ['https://www.googleapis.com/auth/datastudio']
 );

 // Append data to the Data Studio dataset
 dataStudio.data.append({
 auth,
 requestBody: {
 data: [data],
 datasetId,
 reportId,
 appendMode: 'APPEND'
 }
 });
});

```

In this example, the script is using the `req.body` object from an express.js application to collect data from the form submission. The script is collecting the `category`, `action`, `label` and `date` fields and the values are assigned to the corresponding keys in the data object. The `date` field is being set to the current date and time.

You will need to replace ‘your-service-account-email’, ‘path/to/privatekey.pem’, and ‘your-private-key’ with your own values. You also need to replace ‘REPORT\_ID’ and ‘DATASET\_ID’ with the IDs of the report and dataset you want to send data to.

It is important to note that in order to use this script, you will need to create a Service Account with appropriate permissions and also enable Data Studio API on your project. You may need to follow the instructions on the following link to set it up: [https://developers.google.com/datastudio/api/guides/authentication](https://developers.google.com/datastudio/api/guides/authentication)

Also, the example script is based on Node.js and Google client library, but you can use any other language or library as long as it allows you to make authenticated requests to the Data Studio API.

---

<div class="post-metadata">

**Author:** ![06401](https://avatars.discourse-cdn.com/v4/letter/0/d07c76/32.png) [@06401](https://community.hubspot.com/u/06401)\
**Post date:** [January 16, 2023, 10:39am UTC](https://community.hubspot.com/t/contact-endpoint-api-integration-and-google-analytics/72547/4 "2023-01-16T10:39:07Z")

</div>

Hi Leonard,

Thank you. However, we do not use Data Studio and i know that Data Studio gets the data from google analytics so i can assume that we can also see data in Google Analytics 4 with this method,right?

Kind regards,

Sebnem

---

<div class="post-metadata">

**Author:** ![Leonard0](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/leonard0/32/64245_2.png) [@Leonard0](https://community.hubspot.com/u/Leonard0)\
**Post date:** [January 16, 2023, 11:10pm UTC](https://community.hubspot.com/t/contact-endpoint-api-integration-and-google-analytics/72547/5 "2023-01-16T23:10:27Z")

</div>

Hi Sebnem,

I’m sorry, for some reason I mix-up GTM and Data Studio sometimes 🤦🏻‍

With an event you can send data to GTM data layer like below (client side). However if you are posting server side, you need a server-side GTM container.

I don’t have any experience with a server-side setup unfortunately. You need to check out documentation about that, here for example: [Google Tag Manager - Server-side &nbsp;|&nbsp; Google for Developers](https://developers.google.com/tag-platform/tag-manager/server-side)

```lia-code-sample
 window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
 'containerId': 'GTM-XXXXXXX',
 event: 'contactCreated',
 eventCategory: data.category,
 eventAction: data.action,
 eventLabel: data.label
 });

```
