# Mautic Contact ID to G. Analytics User ID

**URL:** <https://forum.mautic.org/t/mautic-contact-id-to-g-analytics-user-id/4209>\
**Category:** Product Support\
**Created:** [June 24, 2016, 6:44pm UTC](https://forum.mautic.org/t/mautic-contact-id-to-g-analytics-user-id/4209 "2016-06-24T18:44:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://forum.mautic.org/u/Steven)\
**Post date:** [June 24, 2016, 6:44pm UTC](https://forum.mautic.org/t/mautic-contact-id-to-g-analytics-user-id/4209/1 "2016-06-24T18:44:25Z")

</div>

Google Analytics has a feature to analyze individual user behavior, under Audience \> User Explorer. There is a way to assign custom unique IDs to each user being explored. More information about this feature set can be found here: [https://support.google.com/analytics/answer/3123662?hl=en](https://support.google.com/analytics/answer/3123662?hl=en)  
  
  
  
I was wondering if anybody has been able to successfully use Mautic Contact ID values for the User ID values.  
  
  
  
Otherwise, if this has not been done by anybody yet, what might be a few options to get the Mautic Contact ID for known users that are on my site? Ultimately, the current contact ID value would need to be saved to the datalayer js code on the page. How can this be done?

---

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://forum.mautic.org/u/Steven)\
**Post date:** [June 24, 2016, 7:49pm UTC](https://forum.mautic.org/t/mautic-contact-id-to-g-analytics-user-id/4209/2 "2016-06-24T19:49:04Z")

</div>

Thanks kuzmany… off to API land I go…

---

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://forum.mautic.org/u/Steven)\
**Post date:** [June 24, 2016, 6:44pm UTC](https://forum.mautic.org/t/mautic-contact-id-to-g-analytics-user-id/4209/3 "2016-06-24T18:44:25Z")

</div>

Google Analytics has a feature to analyze individual user behavior, under Audience \> User Explorer. There is a way to assign custom unique IDs to each user being explored. More information about this feature set can be found here: [https://support.google.com/analytics/answer/3123662?hl=en](https://support.google.com/analytics/answer/3123662?hl=en)

I was wondering if anybody has been able to successfully use Mautic Contact ID values for the User ID values.

Otherwise, if this has not been done by anybody yet, what might be a few options to get the Mautic Contact ID for known users that are on my site? Ultimately, the current contact ID value would need to be saved to the datalayer js code on the page. How can this be done?

---

<div class="post-metadata">

**Author:** ![Lucas](https://avatars.discourse-cdn.com/v4/letter/l/ba8739/32.png) [@Lucas](https://forum.mautic.org/u/Lucas)\
**Post date:** [July 13, 2017, 10:42pm UTC](https://forum.mautic.org/t/mautic-contact-id-to-g-analytics-user-id/4209/4 "2017-07-13T22:42:01Z")

</div>

Follow the code to add Mautic User ID as Google Analytics Dimension

Step 01) Create a Dimension in GA called “MauticId”.

Step 02) Add the function “readCookie” bellow the GA Script in your Site

`<script>
		function readCookie(name) {
			var nameEQ = name + "=";
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) {
				   return decodeURI(c.substring(nameEQ.length,c.length));
				}
			}
			return null;
		}
</script>`

Step 03) Add the code bellow after the GA Script in your Site.

` //Begin of Dimension : Mautic ID
  var varmtc_id = readCookie('mtc_id');
  var varsess_id = readCookie('mautic_session_id');
  if (varmtc_id == null) {
    if (varsess_id != null) {
        varmtc_id = readCookie(varsess_id);
     }
  }
  if (varmtc_id != null) {
     ga('set','MauticId', varmtc_id);
     alert('Mtc Id : ' + varmtc_id);
  }
  //End of Dimension : Mautic ID`

---

<div class="post-metadata">

**Author:** ![Lucas](https://avatars.discourse-cdn.com/v4/letter/l/ba8739/32.png) [@Lucas](https://forum.mautic.org/u/Lucas)\
**Post date:** [October 12, 2017, 6:07pm UTC](https://forum.mautic.org/t/mautic-contact-id-to-g-analytics-user-id/4209/5 "2017-10-12T18:07:57Z")

</div>

Thanks. I will check.
