APIs & Integrations

Not applicable

Is the google anaytics Client ID in hubspot somewhere?

Hi there,

I’m trying get the google Client ID into hubspot, so I can tie it back to analytics for offline conversions.

  1. Is hubspot already grabbing the CID from analytics already an hiding it somewhere in the api, hidden field?

  2. If not how can I grab the CID out of the google cookie an put it in a hidden field, so I can get it into hubspot?

Thanks for your help!
Steve

0 Upvotes
17 Replies 17
Danylo
Member

Is the google anaytics Client ID in hubspot somewhere?

Hello. Hi. Our Google Tag Manager tag injects GA CID form field into Non Hubspot Forms, that can be still tracked by HubSpot. If you're about to track offline conversions in GA, the CID field is by far not a single one you need to track to bypass GA filter as well as to send a proper GEO of a user, not a server.

0 Upvotes
stepup
Participant

Is the google anaytics Client ID in hubspot somewhere?

@JYousuf : I managed to make it work with the help of a developer, as it was not working properly with Google Tag Manager: 

1. I created a hidden field in our HubSpot form called "google_client_id"

2. the developer implemented this script on our website (I am not a developer, so please double-check it with your IT team before implementing it):

 

<script>
window.addEventListener('load', function (event) {
  function getClientId() {
    try {
      return window.ga.getAll()[0].get('clientId');
    } catch (e) {
      return false;
    }
  }
  try {
    var forms = document.querySelectorAll('form');
    forms.forEach(function (frm) {
      var el = frm.querySelector('input[name="google_client_id"]');
      if (el) {
        frm.addEventListener('submit', function () {
          var ev = new Event('input', {
            bubbles: true,
            cancelable: true,
          });
          if (el) {
            el.value = getClientId();
            el.dispatchEvent(ev);
          }
        })
      }
    })
  } catch(e) { console.error(e); }
})
</script>
0 Upvotes
ralphioooo
Contributor | Diamond Partner
Contributor | Diamond Partner

Is the google anaytics Client ID in hubspot somewhere?


We have just created a HubSpot APP called Analytics Amplifier that helps you do this + push offline events to Google Analytics when they happen.

 

Check it out here:
https://ecosystem.hubspot.com/marketplace/apps/marketing/analytics-data/google-analytics-amplifier-2...

0 Upvotes
Not applicable

Is the google anaytics Client ID in hubspot somewhere?

jgardner,

It works with the tag manager. The solution below will work if you have a "Google Universal Analytics Standard Pageview Tag" setup already and a field called "google_client_id" in your form.

  1. In tag manager create a "Custom HTML Tag" and put the code below in it. Have it trigger on "All Pages" "Pageview" then it will trigger on all your pages, a little messy bit it will work for sure, or you can create a trigger with exceptions for just the pages with the forms.
    3% of the time the value won't make it into the field because the field isn't there yet when the tag fires, I'm working on solution for that hopefully.
<script>
$(window).on('load', function (){
    var clientId = ga.getAll()[0].get('clientId');
    $('input[name="google_client_id"]').val(clientId).change();       
    });
</script>
0 Upvotes
jgardiner
Member

Is the google anaytics Client ID in hubspot somewhere?

Thanks Steve! Will give this a shot and test/validate. Appreciate your help and will report back :slight_smile:

0 Upvotes
gotmike
Top Contributor

Is the google anaytics Client ID in hubspot somewhere?

did this work?

would love to hear how this implementation can be best configured.

0 Upvotes
Not applicable

Is the google anaytics Client ID in hubspot somewhere?

Hi cre,

Yes this works, about 3% of the time the clientID won't make it into the field, my only explanation is some kind of browser plugin/privacy blocker/java script turned off on the user side. I've tested just putting hard coded text into the hidden field with java script and j query with the same result, even with a delay in seconds. So if 97% is good enough, it works :slight_smile:

0 Upvotes
stepup
Participant

Is the google anaytics Client ID in hubspot somewhere?

Hi there,

 

Is this script still working for anyone? I implemented in Google Tag Manager, however it won't work for me. I added the tag and a trigger for "all pages", as well as the hidden field in the form. 

 

Does anyone have any hints on how to get this working? Much appreciated!

0 Upvotes
JYousuf
Participant

Is the google anaytics Client ID in hubspot somewhere?

Hey,

Were you able to get the solution for this? 

I tried via GTM too, but it's not working.

0 Upvotes
ralphioooo
Contributor | Diamond Partner
Contributor | Diamond Partner

Is the google anaytics Client ID in hubspot somewhere?

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Is the google anaytics Client ID in hubspot somewhere?

Hi @steve,

Thanks for posting your solution! For future reference, you can surround multiple lines of code with three backtick marks like this:

```
<script>
$(window).load(function(){
var clientId = ga.getAll()[0].get('clientId');
$('input[name="google_client_id"]').val(clientId).change();
});
</script>
```

Which results in the following:

<script>
$(window).load(function(){
    var clientId = ga.getAll()[0].get('clientId');
    $('input[name="google_client_id"]').val(clientId).change();     
    });
</script>
0 Upvotes
jgardiner
Member

Is the google anaytics Client ID in hubspot somewhere?

We are trying to impliment this within Google Tag Manager....is that possible? If so, what would triggering look like? Would we have it fire on all pages containing forms or with the "form submit" trigger? Thanks!

0 Upvotes
Not applicable

Is the google anaytics Client ID in hubspot somewhere?

Sorry didn't like my script tags I guess, here's the code, add script tags before and after.

$(window).load(function(){
var clientId = ga.getAll()[0].get('clientId');
$('input[name="google_client_id"]').val(clientId).change();
});

0 Upvotes
Not applicable

Is the google anaytics Client ID in hubspot somewhere?

Thanks for the help Mezar!

This code below works for me.

Of course your page where this script lives would have to have a field called 'google_client_id'. Or you can put it in the tag manager as 'Custom HTML'.

A caveat about 3% of the time the clientid isn't captured in the hidden field, anybody have any ideas?

The (window).load is there to wait for the content to load before it tries to populate the hidden field.

0 Upvotes
Mezar
Member

Is the google anaytics Client ID in hubspot somewhere?

Hey there Steve! You could have just emailed me, haha.

  1. Nope.

  2. Create the form field, then put the following script in the section, AFTER the Google Tag Manager and Facebook tracking codes, and BEFORE the closing tag (obviously changing the form field id in the code below):

ga(function (tracker) {
clientId = tracker.get('clientId');
$("#STEVES-FORM-FIELD-ID").val(clientId);
});

You gotta put it in the right place though, because if this Javascript runs before the analytics.js library has loaded, then the tracker object may not exist yet.

I’m always here if you need help.

0 Upvotes
j_wick
Member

Is the google anaytics Client ID in hubspot somewhere?

I am curious if anyone got this to work?

I tried placing the code above and a few variations in the footer and then in a module on the page with no success. Google tag manager is in the page head.

$( document ).ready(function() {
ga(function (tracker) {
clientId = tracker.get(‘clientId’);
$("#FIELD-ID").val(clientId);
});
});

0 Upvotes
jm
Contributor

Is the google anaytics Client ID in hubspot somewhere?

nope… gave up for now.

0 Upvotes