Reputation: 146
I have set up 4 dimensions. My code as follows,
<script>//<![CDATA[
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-XXXXX-1');
gtag('set', {
'user_id': _spPageInfo.userId,
'JobTitle': jobTitle,
'Department': department,
'UserLocation': Location
});
gtag('send', 'pageview');
//]]>
</script>
<script>//<![CDATA[
// <!-- Google Tag Manager -->
(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-XXXX');
// <!-- End Google Tag Manager -->
//]]>
</script>
I have set up dimenstion in tag manager as well.
In debug mode i can see "Conatiner Loaded" instead of "Page Load",
And in datalayer i can not see any event name or dimension name.
After 24 hours also its showing undefined.
Please,Can anyone guide me what i am missing here?
Upvotes: 1
Views: 1057
Reputation: 3847
you'll need to pass custom_map
parameter with your config
command you map your named dimension values to custom dimension. See an example here. Moreover, you'll need to call set
before config
since config
is actually passing pageview hit to google analytics so calling set after config won't affect your data
Eventually, your code would look something like this:
gtag('js', new Date());
gtag('set', {'custom_map': {
'dimension1': 'department',
'dimension2': 'jobTitile',
// the same for other custom dimensions
}})
gtag('config', 'UA-XXXXX-1', { 'jobTitile': 'engineer', 'department':'maintenance' });
Moreover, avoid using both GTM and gtag
code at the same time otherwise you'll get duplicated data sent to analytics.
Upvotes: 1