I want to split test different layouts on my site, and to track this I want to use a Custom Dimension which is named Split and equal to 1 or 2.
I've configured the Custom Dimension in Google Analytics and added the code like this:
// Google Analytics
gtag('config', 'UA-70465331-1'), {
'custom_map': {'dimension3': 'Split'}
});
// Sends the custom dimension to Google Analytics.
gtag('event', 'SplitTest', {'Split': "2"});
However, when using the Google Tag Assistant, the Custom Dimension isn't appearing under Events.
The live page is: https://www.travelden.co.uk/mindblowing-new-hotels-in-the-maldives
Can anyone see where the error is?
Much appreciated!
It is coming through:
You need to be careful to set the event to "non-interaction",
I would also suggest you to not send an event if you don't need it...so something like this:
gtag('config', ''UA-70465331-1', { 'dimension3': '2' });
Doing it this way the dimension is applied when the page is loaded, which is really what you're testing, the layout.
Related
I set up Google Global Site Tag for an Angular SPA. I'd like to override the page referrer that is passed to Google.
Use case: after logging in (using oAuth2), the user is redirected to the app. At this point, the url contains sensitive auth data (auth code). This url then gets logged to Google Analytics, which of course should be avoided.
I use the Angulartics2 lib with the GST provider, which internally uses the following code to send page track events to Google (according to Google's documentation on SPA route tracking):
gtag('config', trackingId, params);
By including the following line, I'm able to override the referrer (dr) in the query parameters:
params.page_referrer = 'https://my-custom-referrer.com';
index.html:
<script async src="https://www.googletagmanager.com/gtag/js"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
</script>
Code for tracking the page view event:
gtag('config', 'G-XXXXXXXXXX', {
page_location: 'http://localhost:4200',
page_path: '',
page_referrer: 'https://my-custom-referrer.com',
});
This leads to the following request being sent to google (note the dr properties, which hold the referrer):
As you can see:
The query string uses the correct referrer
However, the request payload still contains the original referrer containing sensitive data
I've tried setting the page referrer with the following line of code:
gtag('set', { page_referrer: 'https://my-custom-referrer.com' });
but this results in the same behaviour.
How can I make sure the request body also uses the overridden referrer? There used to be a setting within the Analytics dashboard to exclude certain referrers, but in the new version (Google Analytics for properties) it has disappeared.
Have you checked out the referral exclusion list?
Generally, if it redirects off your domain for authentication, you don't really want to count it as a referral, because then it will replace the true acquisition data for your users. You want to exclude it so the session is kept intact.
Also, you stated that you're using google tag manager (GTM), but your code and links to the documentation are for gtag.js, which is NOT GTM.
To set the referrer field in GTM, you need to locate the GA tag OR GA Settings tag and under the "fields to set" area, set the referrer field to your liking. Like so:
Though careful that if you override this for everything there could be issues with data accuracy, so you want to conditionally override this based on where it is coming from.
Not a solution, but a workaround. It pushes the current page (without paths or query parameters) to the history, which is then used by Google as the page referrer. At least it allows you to keep sensitive information out of Google Analytics.
history.pushState({ page: 1 }, '', window.location.origin);
I have read some google analytic custom dimension explanations but still can't find a tutorial that explains the steps from beginning to end. I know many have discussed this but many tutorials are incomplete and jumping from the side of the settings in Google Analytics and from the side of laying the code in the project makes me confused.
What I have done,
First I add custom dimension from admin->custom definition->custom dimension
Then, I create a custom report from customization for showing my custom dimension
Then, I put the javascript code in my project
<script>
var test = 'test';
ga('create', 'UA-11xxxxxx', 'auto')
ga('set', 'dimension1', test);
ga('send', 'pageview');
</script>
But, If open the custom report it always returning no data(I have waiting more than a day but still no data)
Is there something wrong with what I've done or are there any steps that were missed?
Any helps will be appreciated. Thanks.
I'm using GTM in my company's online shop, and I installed some other tag via GTM's custom HTML tag, like this:
<script>
//some JS code...
var customParam=[{"key":"value"}];
var jsElm=document.createElement("script");
jsElm.type="text/javascript";
jsElm.async=true;
jsElm.src="https://some_tags.com/tag.js?s=CV";
document.body.appendChild(jsElm);
if(today < some date)
{
SEND GA EVENT here.....
}
</script>
The traditional GA event script
ga('send', 'event', 'XXX', 'pageview', 'some description', 1);
isn't working anymore here.
How do I did this ?
And I heard someone said that I should put data into DataLayer and do some bla bla bla... but I was understanding that too few to try. Is that a right way ?
I am going to answer with another question. Why are you sending events through HTML tags instead of Google Analytics Tag that are build just for that purpose?
I ll work with the assumption that you are new with this tool but the idea is that GTM replaces all old GA code on site.
Just create a new Tag and select 'Universal Analytics' and after that you can choose which kind of information you want on Google Analytics.
Its pretty self explanatory as a tool so i strongly recommend you to forget about those old GA codes and work with what you got.
In addition to this have in mind that you can use custom javascript variables to scrap DOM values in case you need to.
Here is our guru Simo Ahava: https://www.simoahava.com/
If you need anything else just ask.
I currently have landing pages taking the following shape :
http://rootdomain/index.html?ref=[base64encoded-ref]&text=[base64encoded-text]
When I watch my stats in google analytics, I have urls looking like
http://rootdomain/index.html?ref=c3RhY2tvdmVyZmxvdw==&text=bWFyd2Fubg==
but I'd like to see
http://rootdomain/?index.html?ref=stackoverflow&text=marwann for example.
Any idea how to achieve this?
Oki so you can do this, but it can be tricky, so be careful.
Without GTM:
So on the page with Universal analytics, you can actually tell what must be the value that will be recorded. you can decode your path using JS and pass it like below:
ga('send', 'pageview', { 'page': '/YOUR-CUSTOM-PATH' });
Using GTM:
Changing the "dp" value can be accomplished in GTM by setting the desired value in the page field, under "Fields to set":
Let me know if you have doubts.
My current analytics setup looks like this:
this.context.router.listen(location => {
analytics.page(location.pathname, {
title: document.title,
url: `${config.HOST_URL}${this.context.router.createHref(location)}`,
path: this.context.router.createHref(location),
referrer: document.referrer,
state: location.state,
});
});
The amount of data in the location object is pretty minimal. The question is, how do I get information about an item that is loaded in a componentDidMount block into the page tracking?
In this particular instance, I am trying to add information about an artwork that a user is looking at into Google analytics as a custom dimension. The link below shows how it would normally be added.
https://support.google.com/analytics/answer/2709828?hl=en#example-hit
I'm using react-router v2
From the information given, I'd say your best bet is on the pages you want to add more data put a condition in the listener to NOT log if loading that page. Then in the componentDidMount where you have the data call the analytics for the page.
Basically just override it for those pages that need more data.