Client ID is the anonymous cookie identifier that Google Analytics assigns to every single browser instance of any given web visitor. It’s how GA calculates the Users metric in views which don’t have the User ID feature enabled.
Sending the Client ID as a Custom Dimension to Google Analytics is absolutely necessary. It’s the only way to get row-by-row reports split by user, and it’s the only way to query for data collected from any anonymous user.
The setup is really simple. You need a Custom Dimension setup in Universal Analytics, and then you simply need to add a new Field to set in your Page View tag (or whatever you want to use to send the data to GA)
1, Create Custom dimension in Google Analytics
Click on admin -> custom dimension
Name and choose the type. There are 3 scopes in Google Analytics: hit, session and user. Here, client ID is user scope, which related to each cookies.
Then click save. After creating the custom dimensions, there will be an associated index number with it. We will use this index number later.
2, Create a variable in Google Tag Manager
First, you navigate to Google Tag Manager, and create a new variable.
Then choose custom javascript
Name that client_id_setter, and input this script
function() {
// Modify customDimensionIndex to match the index number you want to send the data to
var customDimensionIndex = 5;
return function(model) {
model.set('dimension' + customDimensionIndex, model.get('clientId'));
}
}
REMEMBER TO CHANGE THE “customDimensionIndex” IN THE CODE TO THE INDEX NUMBER IN CUSTOM DIMENSION. Here, we must change it to 2
Then save.
3, Change Google Analytics variable
Refer to your Google Analytics variable
Click on More setting
Enter as below screenshot
Then save.
After all changes, you may see the client ID as secondary dimension
Good luck on your Digital Marketing career.
Source: https://www.simoahava.com/gtm-tips/use-customtask-access-tracker-values-google-tag-manager/