I want to add a Custom Variables called Custom Variables to my website.And I defined a datalayer on Google Tag Manager.I also add the code snippet on the page which I want to get the Custom Variable.
<script type="text/javascript">
var external_id = jQuery('#edit-external-id').attr("value");
dataLayer = [{
'externalID': external_id
}];
</script>
I debuged the configuration of GTM.Here's the picture
I got the message.But I can't see the value statics on my Google Analytics.I think the menu path of GA is Audience-Custom-Custom Variable.Am I right?Anyone can help me?
Writing values to the dataLayer does not make them appear in Google Analytics; it just makes them available in GTM.
You need to set up a Google Analytics Tag - there is a tag template for Universal Analytics where you can insert the Google Account id. Use the default "all pages" trigger. Since you are receiving data I assume you already have done this.
Now in GTM go to the "variables" menu, click "new" and select "Data Layer Variable" as type. Enter the key from the dataLayer that you want to be evaluated, i.e. "externalID". Give your variable a name, I suggest to simply use the dataLayer key. Save. Now you can use the variable by calling it via its name surrounded by {{curly brackets}}.
Go back to your GA tag. I assume you want to save the value as custom dimension, since custom variables are deprecated in the current GA version. You need to create a custom dimension in Admin/Property/Custom Definitions/Custom Dimensions. When you create a custom dimension you will get a numeric index to address the dimension by. Go to your GA tag, advanced configuration, custom dimensions and click "add". Enter the numeric index and after that select the variable you want to send.
Custom variables do not show up by default in the standard reports; you can either selected them as "secondary dimension" from the dropdown above the data table, or create a custom report.
First, you must never, ever use dataLayer = [{...}] after the container snippet (preferably don't use it ever). You're overwriting the container snippet by reinitializing it as a new Array. As you can see, in your Preview panel there is no "Page View" event (should be just before DOM Ready), which means e.g. the All Pages Trigger won't work.
Second, "Custom Variables" are deprecated. They've been replaced with Custom Dimensions in Universal Analytics.
Third, did you actually add this variable/dimension to a GA Tag?
Here's how it should work:
1) In your script replace dataLayer = [{...}] with:
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event' : 'variablePushed',
'externalID' : external_id
});
This is the safe way to interact with dataLayer.
2) In GA Admin / Property Settings / Custom Definitions / Custom Dimensions, create a new Custom Dimension with the appropriate scope, and make note of the assigned Index number. If you are unfamiliar with Custom Dimensions, you have some reading to do. Start with https://support.google.com/analytics/answer/2709828?hl=en
3) Create a new Custom Event Trigger for Event Name variablePushed, name it e.g. "Event - variablePushed" (without quotes).
4) Create a new Data Layer Variable for Variable Name externalID, name it e.g. {{externalID}} (without curly braces).
5) Create a new Event Tag, with Event Category: External ID, Event Action: {{externalID}}, and set the Non-Interaction field to True.
6) Browse to More Settings -> Custom Dimensions in the Event Tag, and add a new Custom Dimension. Set the Index number from (2) and set the value to {{externalID}}.
7) Add the Trigger you created in (3) to this Event Tag.
What happens now is that when the externalID dataLayer.push() takes place, the Event Tag fires a non-interaction event to GA (so it won't affect Bounce Rate), which piggybacks the Custom Dimension with it.
Related
We are using Google Tag Manager. It is sending a custom dimension to Google Analytics with a value of {{fc-isSubscribedSession}} variable
The fc-isSubscribedSession variable is a DOM variable that is taken from the data-is-subscribed-session attribute on the page body.
We are migrating our platform. The old user interface makes use of the tag and the data-is-subscribed-session attribute. The new user interface is more like SPA so we are using the data layer to push the data to GTM like
window.dataLayer.push({
'newInterfaceIsSubscribedSession': current_user.is_subscribed?
});
(above is a fragment that is close enough to the real call)
Now the problem is that we must fill the dimension from fc-isSubscribedSession or from newInterfaceIsSubscribedSession.
Do you know if there is a way to fill a dimension from one of two values?
Something like
{{fc-isSusbscribedSession}} or {{newInterfaceIsSubscribedSession}}
I want Google Analytics to send a client calculated value on AMP. I also use Google Tag Manager to embed analytics code on the page.
I want to send a value that is the difference between a time (unix) and current time on device. There's a variable on Tag Manager named "{{Client Timestamp}}" and I define server side the other date. But any time I send the value, get's turned to string (no matter if it's custom metric or custom dimension), for instance:
cm3: 1582720980844-1582641262000
Do you know any way I can achieve this? Also tried with a generated hidden element with the value calculated, but I can't manage the set the correct value on this element without user interaction.
<amp-state id="my_data">
<script type="application/json">
{
"my_date": SERVER_GENERATED_TIMESTAMP
}
</script>
</amp-state>
<span class="element_to_send_from_tag_manager" [text]="Date.now() - my_date">sample value</span>
You are trying to make a calculation inside a text field, that's why GTM is treating it as a string no matter what you do. If you want to run a calculation that is the difference of time between those two variables, use a custom javascript variable and push the result of that inside your secondary dimension.
Example of custom JS variable in GTM:
function() {
var result = {{variable1}} - {{variable2}};
return result;
}
EDIT:
Since we are talking about an AMP container, we cannot do the subtraction inside GTM itself, what we can use instead is the Calculated Metrics functionality inside GA itself.
Im trying to extract parameters from the URL. Then send that data to google analytics via GTM. Using only one tag instead of having mulitple tags for each parameter.
website.com/index?searched=data%7Cdata%7Cdata
The data needs to be seperated. So I've created a variable that seperates each paramater.
function () {
var x = {{URL Query}}.split("|");
var z = x.slice(1, -1);
return z;
}
And a trigger that picks up on click.
I'm fairly new to google tag manager, and i'm unsure of the process to do this. Should I work with Datalayers or do a loop with Custom HTML tag? But then i'm not sure what the code is to send my data to google analytics.
What you need to do is to create multiple variables if you want to capture different parameters in the URL to separate dimensions in Google Analytics. When looking at your code I can see that you want to get the last value separated by "|". Take your code, place it within a "Custom Javascript" variable and then in your Google Analytics tag you can just map the variable to whatever dimension you have set up for this purpose.
Lastly, if you want to pick up more parameters in the URL, just create a a new Custom javascript variable, capture the parameter then map it to another dimension in the Google Analytics tag.
Hope this helps.
I have a Data Layer event push in JS and was wondering if it is also possible to learn the User-Agent of the users triggering the event.
You need to create variable which will return user agent
1) Go to Variables -> New
2) Name: User Agent
3) Type: Custom JavaScript
4) Code:
function () {return navigator.userAgent;}
Then you can use this variable in your tags like that {{User Agent}}
Even more simply, can't you use a "JavaScript Variable" (instead of a "Custom JavaScript" and then just set navigator.userAgent?
Google analytics custom dimension field can be maximum 150 characters and user agent data (when encoded) usually exceed the limit. You need to find a way to shorten the user agent information within a custom js script before sending to GA. You may crop the first 150 character of the user agent information or remove the unnecessary sections or remove the blank characters.
I tried to setup Google Tag Manager. The Pageviews are tracked correctly, but in Universal Analytics I can not see Custom Dimensions.
In Google Universal Analytics:
I have defined some custom dimensions in the Universal Analytics Profile under "Admin" -> "Custom Definitions" -> "Custom Dimensions".
The following Dimensions are relevant:
(Name) (Index)
PageView Author 7
PageView Themenwelt 8
PageView Seitentyp 9
PageView Posttyp 10
PageView Modified Date 11
In Google Tag Manager:
I have added a page Universal Analytics Tag with Track Type "Page View" and the following settings for "Custom Dimensions":
(Index) (Dimension)
7 {{Tracking Variable Posttyp}}
9 {{Tracking Variable Seitentyp}}
8 {{Tracking Variable Themenwelt}}
7 {{Tracking Variable Autor}}
11 {{Tracking Variable Modified Date}}
The values for the dimensions are fetched via Macros, using the "Javascript Variable" Macro.
Example for such a macro is just:
Global Variable Name: window.analytics_tracking_params.Author
The Variable is defined in the Website content, before the tag manager code.
When I go to the debug mode of tag manager, I can see the event being triggered, with the following debug entry for "Dimension":
{
7: Tracking Variable Autor,
8: Tracking Variable Themenwelt,
9: Tracking Variable Seitentyp,
10: Tracking Variable Posttyp,
11: Tracking Variable Modified Date,
}
The Macros resolve correctly to the values set on the website.
----------> I believe that the Google Tag Manager Setup is correct.
Again, in Google Universal Analytics:
I have created a Custom Report ("Customization" -> "+New Custom Report") with the following settings:
Metric Groups: Pageviews (Users)
Dimension Drilldowns: PageView Posttyp (Custom Dimensions)
In the report table below the Chart, there is only this message "There is no data for this view.".
This happens regardless of which Custom Dimension I chose.
----------> I believe that the Settings in Google Universal Analytics are correct, but apparently something does not work as expected.
It seems the Data is not correctly sent to Universal Analytics OR Universal Analytics is not able to process the Data and display it. Is there anything I might have forgotten or misunderstood?
I encountered a similar problem with my GTM configuration. I had my macro retrieving the values for my custom dimensions set up to fill in an empty string as a default value (see checkbox for default value: "To set the default value to be an empty string, select this option and leave the text field blank.").
Unfortunately my custom dimension was overwritten at some places with the empty string, so in GA pagehits etc. were recorded but the custom dimensions have been set to blank.
I changed that with unchecking the default value box, so instead of a empty string a nil value (or in JS: undefined) will be used instead. With that setting my custom dimension haven't got overwritten again with empty strings.
Maybe that might fix your problem as well?
see if your custom dimensions can be seen as aseconday dimension in the events sections. If you can you are probably look at standard user reports. Custom reports easily populate custom dimensions.