Problem
Google Analytics shows a large number of unassigned users.
Context
We only collect data from inside the secured area of our web-application - thus no unassigned users should be counted. Most of the unassigned sessions originate from direct links in emails that go out to our users.
App Details:
- Angular 1.x
- SPA
Tracking Code in HEAD:
<script>
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
e.src=’//www.google-analytics.com/analytics.js';
r.parentNode.insertBefore(e,r)}(window,document,‘script’,‘ga’));
ga(‘set’, ‘anonymizeIp’, true);
ga(‘create’,‘UA-XXX-1’, ‘auto’,
{‘siteSpeedSampleRate’: 80}
);
</script>
User ID call in top of BODY
<script>
setTimeout(function(){
ga(‘set’, ‘userId’, document.getElementById(‘userId’).innerHTML);
}, 8000);
</script>
I appreciate any thoughts from you as we have tried many things and can't figure out whats wrong here...
Thanks in advance!
Regards,
Lennart
Related
I've implemented purchase events on a site using tagmanager. Now, I'm facing an issue with the total event count and revenue. When I compare the number of purchase events and revenue on the GA4 dashboard with the count and amount displayed on the backend of the website, the GA4 dashboard shows less count.
When a user makes a purchase, they will be redirected to a thank you page (there are a total of 5 thank you pages depending on the type of purchase) and from these thank you pages, we push the data to the data layer. The tagmanager tracking code is added in the head and body of the thank you pages, only on the thank you pages.
Below is the script we use to push data to the data layer.
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ ecommerce:null })
window.dataLayer.push({
event: 'purchase',
ecommerce: {
currency: 'EUR',
value: #Price#,
transaction_id: '##TransactionID##',
items: [{
item_name: '#Item Name#',
item_id: '#Item Name#',
price: #Price#,
quantity: 1
}]
}
});
</script>
Below is the difference in the count of events.
27-09-2022 - Backend - 1199, GA Dashboard - 1136
26-09-2022 -Backend - 1925, GA Dashboard - 1306
25-09-2022 - Backend - 866, GA Dashboard - 818
24-09-2022 - Backend - 929, GA Dashboard - 893
23-09-2022 - Backend - 1375, GA Dashboard - 1292.
When I used the Chat option in GA4, they suggested that it is an issue with the Tag Manager.
But I couldn't figure out it.
Could someone please enlighten me as to fix it? Thanks in advance.
A discrepancy between 5 and 10% between the database and Analytics data is physiological. There are several reasons why this can happen: JavaScript error, Ad-blocker, type of browser used by the user, slow loading of the page, user not returning to the website from the payment system, consent mode, etc...
In your case, apart from one case, the others are all around 5 or 6%. I would say that everything is normal.
To have 100% of the transactions you should adopt a server-to-server conversion tracking system.
I have implemented a feedback star rating on my website at the bottom of each page. They can select one to five stars and optionally send free-form comments. I have implemented gtag.js to send the star rating integer and comments to my GA4 dashboard. Code snippet is below; I have omitted the JavaScript which allows the user to set the variables, but this is working.
<script async src="https://www.googletagmanager.com/gtag/js?id=MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'MEASUREMENT_ID', {
'custom_map': {
'rating_dimension': 'rating_key',
'comments_dimension': 'comments_key'
},
'rating_key': 'this.value',
'comments_key': 'commentsValue',
});
</script>
gtag('event', 'rating_event', {'rating_key': this.value });
gtag('event', 'comments_event', {'comments_key': commentValue });
I went under Configure>Custom definitions and added the dimensions under the Event scope.
The data is being sent as an event, because this is something the user can optionally do on a page. I have verified that the data is sent to GA, I have the Google Chrome GA Debugger, and can see that it is arriving in the Realtime report under Events.
I would like to build a report which shows the page title/URL, the number of views, the length of time spent, along with its average star rating and any comments. I would like to have some adjustable controls so that I can configure this to be shown for a specified length of time. For example, if the page is modified, I can see the average rating before and after the change. Unfortunately, I am not able to build even the most rudimentary view of this data in the new GA web interface. I tried to modify various existing reports to include my custom dimensions, but they don't offer this option. I went under Explore and tried to add a Freeform report, but I can't get the data to show up there either, it only counts the number of times the event has occurred, which is not what I care about at all.
I have gone to a lot of effort to send the data to GA and had expected to be able to access the data and build a basic report.
Is it that you are unable to add custom dimensions and metrics to the free form exploration? Or when you want to add dimensions or metrics, they don't even show up in the custom section?
Normally you have to wait more or less (some say up to) 24 hours before being able to use custom definitions (metrics and dimensions) in any report.
this might not be your case, but I found your post looking for an answer to my problem, which is the custom metrics and dimensions are there, I am just unable to add them to the report, it looks like a bug, I click the + button, check the custom dimensions and nothing happens.
We have implemented Google Analytics Ecommerce tracking in our web site. We have noted that there are some missing transactions from Google Analytics. Only some data get missing and other transactions are recorded correctly.
There is no specific pattern to those missing orders (e.g. the products that are selected, the device they are using...etc).
Below is the code snippet that push transaction data to analytics.
var products = [];
for (i = 0; i < cart.lines.length; i++) {
var cartItem = cart.lines[i];
if (cartItem != null && cartItem != 'undefined') {
products.push({
'name': cartItem.cartProduct.name + ' ($' + cartItem.cost + ')',
'id': cartItem.cartProduct.id ,
'price': cartItem.cost,
'brand': 'My Brand XXX',
'category': cartItem.category,
'variant': 'My Brand XXX',
'quantity': 1 // Iterating item by item therefore hardcoding quantity to 1
});
}
}
// Pushing ecommerce transaction data to data layer
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'ecommerce': {
'purchase': {
'actionField': {
'id': cart.referenceNumber, // Transaction ID. Required for purchases and refunds.
'affiliation': store.name,
'revenue': cart.totalPrice, // Total transaction value (incl. tax and shipping)
'tax': 0,
'shipping': cart.deliveryCharge,
'coupon': ''
},
'products': products
}
},
'event': 'purchase'
});
}
Note that I have the fully populated 'cart' and 'store' objects accessible.
Appreciate if anyone could help to figure out what's causing this.
Well, Your code seems fine. There isn't any specific way to identify the way what is causing this issue.
You can implement exception tracking in above particular code, by that you will get to know the possible reason which is causing the issue.
To implement exception tracking using GTM you need to wrap up the above code in try catch block and in catch block you push the datalayer event with the exception detail. On other side in GTM configure the exception tracking tag.
Hope this will help you. Let me know in case of any help needed to implement exception tracking.
As Google Analytic is Javascript based platform, there could be a lot of reasons the transaction could be missing, some of the obvious reasons are outlined below -:
Ad blocker is enabled on your browser
JavaScript is disabled
Cookies are turned off
Customer left the page before transaction was sent to Google
Analytics
Payment gateway is not redirecting customers to your order
confirmation page
Order confirmation page may not load for certain payment methods
GDPR extensions can also prevent transactions from reaching Google
Analytics
In the past we have used one of the extensions for our Magento 2 site to sync missing orders between Magento and Google using Measurement Protocol API
Whatever platform you might be using, Measurement Protocol API could be utilised to synch orders between the two system and give you 100% sales data view in Analytics.
If you use a third-party payment processor for some but not all transactions - common example, you accept credit cards on your website but you also accept PayPal payments where the buyer is taken to the PayPal site to complete the transaction - the ones who leave your site to pay are often not counted.
Two reasons: one, many buyers leave straight from PayPal - they never view the order confirmation page where your tracking code is set to send the data to GA.
Two, they're tracked separately because they've technically left your website and then returned, so you need to set up cross-domain tracking to associate them with the correct user session.
(I know this answer is rather late for the OP but thought it might help someone else in a similar situation.)
Recently we update our system to work with google analytics universal. We migrated the property to use universal analytics, and a few days later, we made the code changes according to the guide: https://developers.google.com/analytics/devguides/collection/upgrade/guide
We made the change to also use the User-ID functionality. Every event or page view is tracked normally, but the goals completions (which are in the end when a user reaches a specific page).
We introduced the user-id on the midday of the August 6th, and as you can see, the day after the goals were 0 (although because of our database, I can tell was about 25). Day after (8th), the goals (as said before, pageviews with the user-id set) were tracked normally again. Day 9th only a few (and were much more). From that day on, not at all are tracked.
In the beginning I believed that it takes longer to analytics to put the data together because of the user-id, but it seems to me very strange.
The code i am using is:
<!-- Google Analytics Universal-->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxxx-y', {
'cookieDomain': 'xxxxxxx.xx',
'siteSpeedSampleRate': 25
});
{% if userId is set %}
ga('set', '&uid', userId);
{% endif %}
ga('send', 'pageview');
Everything pretty straightforward, and I am also using the google analytics debug tool to check if all the data is sent, and yes, it's sent. In addition to that, if I reach a page that tracks a goal myself, I can see my session in the real time, so data is sent to analytics.
That's why I am thinking that I am missing some configuration from the google analytics side. I already created a user-id view and the data there contains the same information, but only from 6th august, when user-id functionality was started to be used.
Anyone has an idea or has the same trouble?
Thanks!
If you're using a debug tool and have verified that the user ID is in fact being sent as part of the hit to Google Analytics, then that means you're doing everything correctly on your end.
I copied your exact code, replaced the userId variable with the string 'foobar', and I was also able to verify that the hit was sent correctly, including the string 'foobar'. Here's what it looked like:
http://www.google-analytics.com/collect?
v=1&
_v=j25&
a=1335799492&
t=pageview&
_s=1&
dl=http%3A%2F%2Flocalhost%2Ftest.html&
ul=en-us&
de=UTF-8&
sd=24-bit&
sr=2560x1440&
vp=1605x611&
je=1&
fl=14.0%20r0&
_u=cACAAET~&
cid=2022234602.1393626891&
uid=foobar&
tid=UA-XXXX-Y&
z=304825725
If the data is not properly showing up in your reports, and you're sure that everything is set up correctly for your userId-enabled view, then it could be a bug, and if so, the best thing to do is simply report it to Google.
The best place to report the bug is here:
https://code.google.com/p/analytics-issues/issues/entry
UPDATE (08/26/2014)
It looks like there's already a bug entered for this issue. You can star it here to be notified of fixes/updates: https://code.google.com/p/analytics-issues/issues/detail?id=477
ga('set', '&uid', userId);
Is that printing a literal userId or does that actually work? Try:
ga('set', '&uid', '{%=escape(userId)%}');
have you tried? ga('create', 'UA-XXXX-Y', { 'userId': 'USER_ID' });
information directly from the documentation found at User_id
I'd like to track how many people hit my website that might be logged into LinkedIn. Depending on the results, I might add an interactive LinkedIn section using their API.
I already have the Javascript logic to detect if they're logged in. My question is what is the best approach to log this result? Can Google Analytics do it with a custom variable or event detection?
I'd love to report on something like, "10,000 visits to my website, of which X number of visitors were logged into LinkedIn".
Any help would be appreciated!
I believe Google Analytics Custom Tracking Variables would do the trick. Something along the lines of:
_gaq.push(['_setCustomVar',
1, // variable slot
'LinkedInUser', // variable
'true', // value
1 // variable scope, 1=visitor
]);
_gaq.push(['_trackPageview']);
For custom variables (not that is this is a user-triggered event after the initial GA page load logic, a call to _trackPageview is needed to push the data back to GA), or:
_gaq.push(['_trackEvent',
'PageView',
'LinkedIn'
]);
For custom events. Just pop something similar to that into your JS routine that checks for authed LinkedIn users.