Track Add To HomeScreen Web App in Google Analytics - google-analytics

I have a mobile web app with the Add to Home Screen functionality working well. I am trying to determine how to use Google Analytics to best track the app usage for those who have installed the app to their home screen. There doesn't seem to be a default way to see if an app is in standalone mode in analytics, is there a best practice for Google Analytics to track apps installed on the home screen?

You can detect if the app is launched in PWA mode. Refer this answer on how to do it.
Once you know your app is running in PWA mode, you can use a different tracking ID to track the PWA applications separately or you can use the same tracking ID and use the traffic source with appropriate value based on your PWA detection.

Derived from #Anand's answer I implemented the following:
Set up a separate Google Analytics stream for the installed app. This will have its own measurement ID tag
Detect which display mode is being used and select the appropriate tag to provide to Google's gtag.js. The assumption is that if the display-mode is not 'browser' then it is the home screen version of the app
<script async src="https://www.googletagmanager.com/gtag/js"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
const measurementId = window.matchMedia('(display-mode: browser)').matches ? 'G-TAG-A' : 'G-TAG-B';
gtag('config', measurementId);
</script>
Note, replace 'G-TAG-A|B' with your two Google Analytics supplied measurement IDs

Related

Moving from Universal Analytics(UA) to GA4

Currently I have a setup where the Google Analytics events for the Android and iOS apps were being tracked on the Firebase console itself (which I believe is called UA). But that data is not visible at all in the Analytics Console. Now I want to move to GA4, such that I can use the latest features. I also want our existing data which has been captured under UA to be visible in the Analytics console in the GA4 property. I have tried creating a GA4 property, but over there, it was asking to add a new Data Stream, which is leading to creation of a new Firebase Project, and thus would require us to move all our other functionalities like Firestore to the new project as well, which is not feasible. Is there a way so that all my existing and new events which are fired from the Apps are registered in the Analytics Console, be it using UA or GA4 (GA4 would be preferred).
PS - I found ample number of articles to use tag id for Websites, but none for Android or iOS Apps.

Is it possible to track basic analytics data without asking consent?

hope someone can help with this problem we are having.
We are using google analytics on several websites with the only purpose to have a visits counter of each one.
We do it using Google Analytics Reporting API and this is the only reason: we don't use it for marketing purposes or to analyze audiences or behaviour. We want to understand if this is compliant with GDPR since we don't ask cookie permissions to users on each website or if is there a way to just use Analytics as counter without showing any consent message to users.
Let me know
Thanks
There is no universal rule for all UE member states, however many guarantors (such as the Italian one) have stated that by reducing the identifying power of an analytical cookie, this cookie can be considered a technical cookie.
A technical cookie does not require acceptance but can always be provided
In order to reduce the identifying power of the Analytics cookie, it is possible to use the IP Anonymization (or IP masking) setting in Google Analytics hit which removes the last octet from the IP that sends (automatically) with the call to the Google servers. In this way, the user cannot be geolocated and the GA cookie is considered to be of a technical nature.
With Universal Analytics you need to add a setting to the tracking code while with Google Analytics 4 IP anonymization is the default.
If you use gtag, the code is something like this:
<!-- IP anonymization with gtag.js - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'GA_TRACKING_ID', { 'anonymize_ip': true });
</script>

How to configure multiple tracking code of Google analytics

I have created two accounts (www.websiteUrl1.com and www.websiteUrl2.com) in my Google Analytics account.
Actually www.websiteUrl1.com and www.websiteUrl2.com shares the same code base and deployed on single server and single portal.
Now we want to track traffic of www.websiteUrl1.com and www.websiteUrl2.com separately. Each this account has their own tracking code and not sure how can we add another tracking code there.
This is how we have configured tracking code in our website as
<!-- Global site tag (gtag.js) - Google Analytics. www.websiteUrl1.com -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXXX-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXXX-1');
</script>
Can you please guide how can we configure another urls (www.websiteUrl2.com) tracking code?
I would switch the analytics code server side based on the referring domain. If the domain is www.websiteUrl1.com write out tracking code 1, if it is www.websiteUrl2.com write out tracking code 2.

Google Analytics - domain setting required for test?

I am trying to set up a test page for Google Analytics.
I selected the web option for the project, specified the company url as a placeholder.
We will not run the GA code on the page, but I had to fill something as it was asking.
Pasted the gtag code into a test page to test it.
Open in browser on my machine, see no traffic on the Live analytics tracking page.
Question - does the tracking have to happen on a page of the domain? Or, can it come from anywhere (my desktop)? I use GA in a different project for mobile apps where events work, but this is a internal web app and it's failing at the minimum code.
<html>
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-123456789-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-123456789-1');
gtag('event', 'TEST');
</script>
</head>
<bod>
HELLO WORLD
</bod>
</html>
Analytics snippet need to set a cookie to work, otherwise if you try to open an html page from desktop you will receive an error in the console: Cookie write failed.
If you try to copy and run your code in an online tool for script testing, like https://jsfiddle.net/, you will see that the tracking works correctly (the pageview and event is sent to the Analytics Property).
If you created the Analytics View recently it is likely that it will take some time before seeing the results (even in real time).

How would I have GA track an event that happens on another site?

So I am working with a third party self-contained landing page for a client but I would like any conversions on this site to be tracked to the client's website's google analytics account (or GTM). So, for instance, when the form on the landing page gets submitted, it would fire an event on GA, or when the user downloads a pdf from the success page.
there was a link() function in ga.js, but there doesn't seem to be an equivalent in analytics.js
Just need an example of the code and where on the landing page should it go?
For GTM, use tracking form submission events
On the PDF download event, set up an event tag for when they download the PDF.
Note, if the third-party landing page is on a different domain, you will need to setup cross-domain tracking to ensure your traffic information is correct.
Google Analytics collects and aggregates data based on tracking ID (some like UA-123123-1). Data collection is realized over the HTTP request to https://www.google-analytics.com/collect endpoint with tracking ID as an URL parameter. There is no built-in limitations for analytics data to be sent from different domains. So you may send a proper request from any 3rd party page or server and this will be tracked within a client's google analytics account. You only need to know client's tracking ID.
Within your page you may just place a common analytics snippet
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_TRACKING_ID');
</script>
and replace the GA_TRACKING_ID with client value. Note that only location.path would be reported in the client's Google Analytics.So if your landing page doesn't have the path part it may be mistakingly reported as the main page / of the client's site. To prevent this you may use some arbitrary values to be used in the report and pass them as a parameters with gtag(...) call:
gtag('config', 'GA_TRACKING_ID', {
'page_title' : '3rd party landing page', // will be used in reports
'page_path': '/landingpage' // will be used in reports
});

Resources