How to set `ga_session_id` with google tag manager (GTM)? - google-tag-manager

I would like to set the ga_session_id that gets reported in google analytics (along with other event parameters) dynamically. With global site tag (gtag.js) I can make the following call to set the ga_session_id:
gtag('config', 'GA_MEASUREMENT_ID', {
session_id: 'my_custom_session_id'
})
How can I accomplish the same thing in GTM?

Set the field session_id in the GA4 settings tag.

Related

How to assign Google Tag Manager Custom Variable to Google Analytics Custom Dimension

I am new to Google Tag Manager and Google Analytics. Having set up basic tags in GTM that are mapped to Google Analytics I want to get improved insights by using HTML meta tag data To that end I have created a custom GTM variable with the following JS:
var metaNames = ["foo", "bar", "blah" ];
var metas = document.getElementsByTagName('meta');
var content = undefined;
for (i = 0; i < metas.length; i++){
if (metaNames.contains(metas[i].getAttribute("property"))){
content = metas[i].getAttribute("content");
}
}
return content;
}
Having read Google documentation and searched the web I cannot figure out how to map the GTM variable to a GA "Custom Definition" or "Custom Metric". The "User Property" / "Event Parameter" field in GA does not appear to correspond to the GTM variable.
I want GA to use the GTM variable to produce analytics based upon the page meta data properties identified above.
Any assistance would be gratefully received.
Thanks and regards,
Andrew
I have figured this out, under GTM Tag configuration the GTM variables need to be mapped to GA4 "Fields to set" or "User Properties". The variable will then be sent as part of the event fired by GTM

Issue with Dynamic Remarketing Tag. The Product ID parameter is missing in 99% of the activity

When I go to Tag Google Ads details, I have this issue: "The “Product ID” parameter is missing in 99% of the activity of your Google Ads Tag".
Note, I implemented Dynamic Remarketing Tag via Google Tag Manager. In setting up Tag "Remarketing Google Ads" I inserted:
ID Conversion: XXX-XXX-XXX;
Custom Parameters: Use Data Layer {{google_tag_params}};
Trigger: All pages.
Following you can see source code html for a product page that contains ecomm_prodid, ecomm_pagetype, ecomm_totalvalue:
<!-- BEGIN: Google TagManager Remaketing -->
<script>
var dataLayer = window.dataLayer || [];
dataLayer.push({
'event':'remarketingTriggered',
'google_tag_params': {
'ecomm_prodid': '721',
'ecomm_pname': 'MAGLIONE GIROCOLLO IN LANA',
'ecomm_pcat': 'home',
'ecomm_pagetype': 'product',
'ecomm_totalvalue': '20.00'
}
});
</script>
<!-- END: Google TagManager Remaketing -->
So, I created in GTM a variable called google_tag_params with:
Data Layer Variable Name: google_tag_params;
Data Layer Version: Version 2.
As seen before, I used this variable in Remarketing Google Ads Tag, trying to capture at least: ecomm_prodid, ecomm_pagetype, ecomm_totalvalue needed to Display Remarketing.
When I use GTM in preview mode I have this:
Send dynamic remarketing event data: false
Variabile di livello dati:
{ecomm_prodid: '721',
ecomm_pname: 'MAGLIONE GIROCOLLO IN LANA',
ecomm_pcat: 'home',
ecomm_pagetype: 'product',
ecomm_totalvalue: '20.00'}
ID conversione: 'XXX-XXX-XXX'
Parametri personalizzati: 'DATA_LAYER'
Problem is issue "The “Product ID” parameter is missing in 99% of the activity of your Google Ads Tag" is still there.
I tried also check via Tag Assistant with Product Feed ID XXX-XXX-XXX, but I got this alert: Some products are not valid.
When I check on Metadata request in Tag Assistant I got this "event:gtag.config" and not parameters.
I searched for days on web, but did not find any solution.
Could you please assist me?
Thanks,
Francesco
Try the following:
Create a dataLayer variable for each of your dynamic remarketing variable.
google_tag_params.ecomm_prodid
google_tag_params.ecomm_pname
google_tag_params.ecomm_pcat
google_tag_params.ecomm_pagetype
google_tag_params.ecomm_totalvalue
Use the following custom event as you have in the dataLayer event field.
Use the manually specify on your AdWords tag:
Verify the implementation by checking in your browser network tab, filtering by the keyword random. You should see the dynamic remarketing request along with the key/value you've provided.

GA/GTM Custom Dimension Error (Undefined)

kindly ask you to help me with custom dimensions, as i'm newbie for GA/GTM and did everything per manual.
1) So i created 3 new dimensions for ecommerce in GA:
here is dimensions from GA with indexes
2) I've created snipped in GA and added it into head section of my site:
<script> gtag('event', 'page_view', {
'send_to': 'AW-XXXXXXX',
'ecomm_pagetype': 'page_type',
'ecomm_prodid': 'product_ids',
'ecomm_totalvalue': 'total_value',
'user_id': ‘userId’ }); </script>
along with global site tag.
3) Finally i've created new variables in GTM:
for example for page_type
and in Tag itself.
but i constantly getting error on debug:
{index: '1', dimension:undefined}
screenshot is here
will really appreciate any help!
p.s. sorry for links with images instead embedding, i have not enough reputation here yet.
You clearly are mistaken the gtag which stands for global site tag with the tag manager code.
Instead of using gtag use dataLayer.push, this is the method to push information to Google Tag Manager.
An example:
dataLayer.push({
'ecomm_pagetype' : Variable1,
'ecomm_prodid' : Variable2,
'ecomm_totalvalue' : Variable3
});
Here you have the docs for further reference: docs
Remember to place this tag under the Tag Manager snippet. or remember to initialize an empty dataLayer as the doc states.
Code on page
On your page, before your GTM container snippet add the following (I've used sample values for type, id and value), your code should look like below:
<script>
dataLayer = [{
'ecomm_pagetype': 'MyPageType',
'ecomm_prodid': 'EXAMPLE0000001',
'ecomm_totalvalue': '4000',
}];
</script>
<!-- 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 -->
GTM - Data Layer Variables
In GTM, create 3 data layer variables for "ecomm_pagetype", "ecomm_prodid", "ecomm_totalvalue" like so:
Type in the key(name) that's in the datalyer object, you can set a default value if you like, otherwise, it will be "undefined" for pages without this variable defined.
Next create a "Google Analytics Settings" variable, this is to simply GA tag configuration, we will link the custom dimensions here.
Put in your own GA property ID, under "More Settings" expand to "Custom Dimensions", click on "ADD CUSTOM DIMENSION". Put in "1" for to reference the index for "ecomm_pagetype" CD in GA. For value, use the variable we created earlier. Do this for all 3 CDs.
Now your Variables page should look something like this:
GTM - Tags, adding CDs to GA tag
Now for your tag. You should have a Google Analytics tag configured in GTM. Looks like you know how to do that, to add the custom dimensions by using the new "My GA Variable" under "Google Analytics Settings". Don't forget to have this trigger on "All pages" or pick your own trigger as you see fit.

Universal Analytics tag with custom event and custom variables

I want to create a Universal Analytics tag (with enhanced e-commerce enabled) in Google Tag Manager, firing on custom event, ex.: uaEvent with two custom variables, ex.: uaVar1 and uaVar2.
I already created Data Layer Variables (uaVar1 and uaVar2) and the custom event trigger uaEvent in my GTM container. I'm pushing following data:
dataLayer.push({
'event': 'uaEvent',
'uaVar1': 'value',
'uaVar2': 'value'
});
and firing uaEvent on form submit.
Question
How should I configure my tag in Google Tag Manager container so that 'uaVar1' and 'uaVar2' will be visible and connected to uaEvent in Universal Analytics panel ?
Custom variables have been deprecated in Universal Analytics, so you should now use and configure Custom Dimensions under the Properties column in the GA interface. You will need to define the index and scope. Once you have done that, then for the tag that you want to associate your custom data with in GTM, you will need to specify, under the Custom Dimensions section of that tag, the name of the dataLayer variable for your particular Custom Dimension as well as the index.

How can I make sure that gtm send the pageview fast?

I am making the change from the basic analytics code to google tag manager since I need it to track impressions for certain elements. While testing when the pageview fires, I get this warning :
"This page took a long time to send a pageview hit to Google Analytics. Users could be clicking away from your site before it records a pageview."
Google tag manager requires adding the code at the beginning of the body (I tried adding it in the header just in case it helps with that warning, but that didn't work).
Probably GA is not the best choice for such task. GA is well-tailored for pageviews, but not for custom actions.
I solve similar issue with http://www.devmetrics.io analytics. To track impressions for certain elements on my page: 1) add for each of this elements trackvisible css class 2) using setInterval check visibility every few seconds.
Example code using jQuery and devmetrics analytics:
$('.trackvisible').each(function( index ) {
if ($(this).visible()) {
var tag = 'element.' + $(this).attr('id');
devmetrics.userEvent('impression', [tag]);
}
});

Resources