Mautic Contact ID to G. Analytics User ID

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



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?

Thanks kuzmany… off to API land I go…

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

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?

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

Thanks. I will check.