How to set custom ID (user id) in microsoft clarity? - google-tag-manager

I want to send a custom user id to Microsoft clarity from GTM and write this in Tag manager.
<script type="text/javascript">
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "99999999");
var userId = {{Is Logged In}} ? {{userid}} : 0 ;
window.clarity("identify", userId)
</script>
but when I filter my user id or even 0 in custom user ID field in the filter section, it doesn't find anything.
what should I do now?

Related

Google Analytics 4 custom data to track app tenant and user activity

Somewhat new to GA. I think I want custom dimensions and metrics but unclear how to implement this.
My app is behind a secure login page and once logged in each user is signed in to a tenant (company) and has a user ID. I want filter the activity for a particular tenant and / or user.
UPDATE
Here is the code the tag manager had me insert after setting it up (redacted my account into):
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','XYZ-XXXXXX');</script>
<!-- End Google Tag Manager -->
Here is what I had before (the existing js and config tags) and added the additional 4 tags at the end). The <%= %> are Rails code tags.:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-B0KXZBVWXH">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXX');
gtag('company_id', '<%= current_company.id %>');
gtag('company_name', '<%= current_company.name %>');
gtag('user_id', '<%= current_user.id %>');
gtag('username', '<%= current_user.name_full %>');
</script>
Here is my tag manager page:
I am trying to push this info to GA. I would like to generate reports etc and get a handle on which users and clients are using the site.
With GTM, you have to create a Google Analytics 4 Configuration tag and use Fields to Set to set persistent parameter values for all pages that fire the given tag. In your case, to set a user ID, add a row to Fields to Set and set the Field Name to user_id, and the Value to a Tag Manager Variable that returns the user ID.
https://support.google.com/tagmanager/answer/9442095?hl=en
The value of the user_Id have to pass to pushed to the dataLayer, or written in the page (in a JS variable) and then retrieve it, when you know it after the user login.

Show custom dimensions values in google analytics

My goal is to have user email address in google analytics reports so I can build custom reports for client.
For this, I added a custom dimensions "cdUserEmailAddress" under admin --> custom definitions --> custom dimensions
I set it's scope to session.
I set the following code in my page to add a test value but it does not add the value anywhere that I can find on google analytics dashboard.
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
dataLayer.push({
'cdUserEmailAddress': 'test#test.com',
'event': 'sessionUserLoggedIn'
});
gtag('config', 'UA-xxxx-x');
ga('create', 'UA-xxxx-x', 'auto');
ga('set', 'cdUserEmailAddress', 'test#test.com');
ga('send', 'pageview');
console.log('working 2');
</script>
This did not work.
I then went to Google TagManager (since one of the articles I read suggested I need to set that up too) and added a user data element there.
Pasted the auto generated code shown below but that did not help either.
<!-- Google Tag Manager -->
<script>(function (w, d, s, l, i) {
w[l] = w[l] || []; w[l].push({
'gtm.start':
new Date().getTime(), event: 'gtm.js'
}); var f = d.getElementsByTagName(s)[0],
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
j.async = true; j.src =
'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', 'GTM-xxx');</script>
<!-- End Google Tag Manager -->
What am I missing?
I looked everywhere for this test#test.com value ...by creating a custom report, under Behavior -> Site content --> AllPages...
I find it no where.
Please help
Thanks
First of all, you should be aware, that sending email (or any other personally identifiable information) to Google Analytics is violating the terms of service.
Newertheless, if you decide to go for any other custom data, the following should be changed in your code. Custom dimensions and metrics are not referenced by their names, but by their ID, which can be looked up in the administration panel of Google Analytics. For further details please check this detailed guide.
So this part:
ga('set', 'cdUserEmailAddress', 'test#test.com');
Becomes:
ga('set', 'dimension1', 'your non-pii data'); //update the number according to your settings
Also, please note, that generally it's not suggested to send data to the same Analytics property directly from ga() calls and GTM, as you need to maintain your tracking settings in parallel, and you can easily send pageview twice, which is usually not desired.
If you decide to go for GTM, then you need to set up a dataLayer variable, that references your key used in the dataLayer (cdUserEmailAddress in your present case), and you need to use this variable in the Universal Analytics settings, where you can set up custom dimension values, also by referring their IDs.

I cannot use Google Tag Manager, dataLayer push doesn't reflect anything on Analytics event panel

GTM snippet put after the GAnalytics one:
<!-- Google Tag Manager -->
<script>(function (w, d, s, l, i) {
w[l] = w[l] || []; w[l].push({
'gtm.start':
new Date().getTime(), event: 'gtm.js'
}); var f = d.getElementsByTagName(s)[0],
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src =
'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', 'GTM-XXXXXX');</script>
<!-- End Google Tag Manager -->
So I'm trying to run on console (from localhost, I tried also on live)
dataLayer.push({'event':'test'});
then when I look ad the Analytics event panel (real time) nothing appears on the graph. Any suggestion or idea why that's happening?
By default, Google Tag Manager doesn't send any data anywhere. When you do a dataLayer.push call, data is simply added to the dataLayer which sits in the client's browser.
For GTM to send data, you need to configure triggers and tags. If you want to setup GTM as passthrough so it sends whatever data you push to it to Google Analytics, here is an example:
https://www.simoahava.com/analytics/create-a-generic-event-tag/
Some general info about GTM:
Variables: they allow you to fetch data from the dataLayer
Triggers: they are rules that define when certain tags should be fired
Tags: they are pieces of code that can do whatever you want (add a banner to your website, send data to Google Analytics etc...).
dataLayer.push({'event':'test'});
It sends data to dataLayer, not to GA.
You can then create a GA Tag with trigger type "Custom event" using name of your event.
I sorted it out firing event straight from gtag (Google Analytics):
gtag('event', <action>, {
event_category: <category>,
event_label: <label>,
value: <value>
});

Google Analytics Gtag Multiple Analytics Account Tracking IDs

From what I can see Google seem to be phasing out analytics.js now in favor of their tag manager.
How do I fire google analytics new gtag tracking code for multiple analytics accounts?
Something like this:
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-108285779-2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-108285779-2');
gtag('config', 'ANOTHER CODE');
gtag('config', 'ANOTHER CODE');
</script>
In short:
Yes, you can add the same type of product multiple times by calling gtag('config', ...) for each respective Google account + property ID you have.
Details:
It's 2021 and I had the same question but was too paranoid to trust this thread's top voted answer because it described a different experience than my own when testing how this works. Firstly, though, in order to answer OP's question in 2021 we have to look at two entries in Google's official docs, because neither entry fully answers the question but when brought together they can give us a bit more confidence in how to solve this:
Can I add more than one type of product using gtag('config', ...)? (Answer: yes.) (Docs)
Can I add more than one of the same type of product using gtag('config', ...)? (Answer: yes.) (Docs)
Here's an example snippet of how I accomplished OP's scenario using JavaScript. If you try this in your browser's console you should see a unique script get added for each ID you set in the below snippet's googleIds array.
Notes:
Notice that the snippet's googleIds array contains five IDs.
Notice that, after running the snippet in your browser console, five <script> tags get set to the page, but that the snippet itself only explicitly built and set one of the tags to the .
The rest of the tags get added after their respective IDs are pushed into the dataLayer, and after the first script is initialized (i.e. the element is constructed + set to the ). The order of these two steps doesn't matter (i.e. You can initialize first and then push your IDs to the dataLayer, or push your IDs to the dataLayer and then initialize).
// An array of IDs I want to load on the same page(s) at the same time
var googleIds = ["AW-00000000", "AW-00000001", "AW-00000002", "DC-00000000", "UA-00000000-1"];
// Setting dataLayer & gtag to window because I'm using a custom code text field in a tag management system
window.dataLayer = window.dataLayer || [];
window.gtag =
window.gtag ||
function() {
window.dataLayer.push(arguments);
};
window.gtag("js", new Date());
// Flag used to ensure script only set with first ID, and rest of IDs are pushed to dataLayer
var gtagScriptExists = false;
// ID validation regex. Only tested with AW-*, but DC & UA are also valid prefixes
var validIdStructure = new RegExp(/(AW|DC|UA)-[0-9]{8,}(-[0-9]{1,})?/);
// Push IDs into dataLayer and set initial gtag/js?id= script to page using first ID in googleIds array
for (var i = 0; i < googleIds.length; i++) {
var gtagId = googleIds[i];
// Validate that the ID being passed isn't a big weirdo
var idIsValid =
typeof gtagId === "string" && gtagId.match(validIdStructure);
if (idIsValid) {
window.gtag("config", gtagId);
// NOTE: gtag script only needs to be set to page once, but each gtag('config', <ID>) that's pushed to the dataLayer will add subsequent gtag/js?id=<ID> scripts to the page
if (!gtagScriptExists) {
// Set initial gtag/js?id=<first ID> script to <head>
var script = document.createElement("script");
script.type = "text/javascript";
script.async = true;
script.src = "//www.googletagmanager.com/gtag/js?id=" + gtagId;
document.getElementsByTagName("head")[0].appendChild(script);
// Update gtag/js?id= script status flag so this initialization script is only set for the first ID, and not all the IDs in the array
gtagScriptExists = true;
}
}
}
Yes, that is correct according to documentation. But it generated no data for me on the subsequent codes until I added
<script async src="https://www.googletagmanager.com/gtag/js?id=ANOTHER_CODE"></script>
Immediately above the code block. Either I stumbled on a working kludge or Google needs to update their documentation.
Yes. You can add multiple accounts, and send to all of them or send individually.
Setup
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXX-1">
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
// Global configs
gtag('config', 'G-XXXXXX-1');
gtag('config', 'AW-YYYYYY');
gtag('config', 'DC-ZZZZZZ');
</script>
And this is the place when firing events
<script>
// This is place firing event
// Send to all
// Send to one: Measure Google Ads conversions
gtag('event', 'conversion', {
'send_to': 'AW-YYYYYY/AbC-D_efG-h12_34-567',
'value': 1.0,
'currency': 'USD'
});
</script>
That seems to be the official way to do it according to the documentation.

linkedin public profile url memberdata plugin

I am trying to create a company directory which will provide a link to an employees linkedin public profile, if the uses chooses to connect.
So on our employee profile page, the user can choose to link their linkedin account to their employee profile. We initiate an oAuth process and we retrieve their hashed linkedin id, which we then store. Great. Now the part that isn't working.
Based on their plugin example, i have this...
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: xxxxxxxxxxxx
authorize: false
</script>
<script type="text/javascript">
function INTEST() {
IN.API.Profile().ids("pU-LBvD_y0")
.fields(['id', 'firstName', 'lastName', 'picture-url', 'public-profile-url'])
.result(function (result) {
profile = result.values[0];
})
.error(function (errorResult) {
var i = 0;
});;
}
</script>
I receive all information except the public-profile-url.
Any help would be greatly appreciated.
I'm sure you have this figured out by now. But for the benefit of others:
When using the JavaScript API you must convert the profile field names from the dashed notation to studly caps. For example first-name becomes firstName. public-profile-url becomes publicProfileUrl
Reference the following API documentation at
http://developer.linkedinlabs.com/tutorials/jsapi_profile/

Resources