danwilson / google-analytics-plugin

Cordova (PhoneGap) Plugin to connect to the native Google's Universal Analytics SDK 3.0
MIT License
693 stars 500 forks source link

Using web site data tracker for mobile app #566

Open premedios opened 4 years ago

premedios commented 4 years ago

Why is this plugin forcing people to create a web site data property to get a tracking number when cordova is supposed to be generating mobile apps and not responsive web sites?

MichielJ87 commented 4 years ago

Hi,

Mainly because google no longer supports the Google Analytics Services SDK's after October 2019, more info here https://support.google.com/firebase/answer/9167112?hl=en This plugin works with the Google Analytics SDK.

When you use this plugin, you can set up your property as an app in Google Analytics. However because support by Google will soon end, this plugin will not be useful after October 2019 (see above).

Instead you can track your cordova app just like a website, without the need for this plugin. So currently many people are pointing this out in the discussions related to this plugin. This way people can continue to track the same kind of information, without making to much changes in their existing applications.

Alternatively you can make use of the Firebase SDK, this way you can set up your property as an app (like recommended by Google). However:

Kind regards, Michiel

xcafebabe commented 4 years ago

Hi there, @victorsosa so unfortunately this plugin has become obsolete, right?

victorsosa commented 4 years ago

For sometime the GA still be supporting this api; except that there is no more SDK development of the API. @xcafebabe I still using the GA website (mobile version) and collecting data.

xcafebabe commented 4 years ago

Well I understand that there is not much interest to show how we can continue using the plugin.

Anyway, thank you for keeping the project alive. Cheers.

Faksprod commented 4 years ago

Hello @MichielJ87

Instead you can track your cordova app just like a website, without the need for this plugin.

Really? Is it simple as this? Could you give us more details about how to make this works?

I would like to use Google Analytics in my Cordova app. Informations found about it after doing researches are a bit blurry to me for now (SDK deprecated, Firebase, etc.). So if finally we don't need plugin at all this would be really simple to integrate.

On my Google Analytics account, I have created a new test account to try to track my Cordova App. Then I put the tracking code given by GA into my index.html file (just after the head tag).

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script>
<script>
   window.dataLayer = window.dataLayer || [];
   function gtag(){dataLayer.push(arguments);}
   gtag('js', new Date());
   gtag('config', 'UA-XXXXXXXXX-X');
</script>

When I run my Cordova app on my local devices (iOS and Android) nothing happen on the "Real time" tab on my GA dashboard.

So I tried to include the tracking code on a test.html file on one of my server and the "Real time" tab on GA increased to 1 user immediately. So the tracking code works.

So I'm curious about how you do to get a "website tracking code" working in your Cordova apps... Any advises?

Thanks!

MichielJ87 commented 4 years ago

Hi @Faksprod This is what I currently have in my html head:

` `

Other tips that I have are:

Kind regards, Michiel

Faksprod commented 4 years ago

Hello @MichielJ87 and thanks for your quick reply. I will try your solution and compare it with the one I found this night (which worked well). Solution found from this blog (French) works using an alternative method. If you think your method is better for some reasons feel free to tell me.

How to use Google Analytics in a Cordova without any plugin:

1 - Create a new account to get a tracking code on Google Analytics (just like you would do for a website tracking code, not for a mobile app)

2 - Download the Analytics.js script from Google (doc)

3 - Include the Analytics.js file to your project into a classic JS script tag. BUT FIRST, you have to find and comment the following line in the Analytics.js file.

if("http:"!=a&&"https:"!=a)throw"abort";

4 - Wait for the DeviceReady event and create your GA tracking object.

ga('create', 'UA-XXXXXX-XX', {
    'storage': 'none',
    'clientId':device.uuid
 });

5 - Then you can send any informations you want to GA to track your app.

ga('set', {
    'appName': 'myAppName',
    'appId': 'myAppId',
    'appVersion': '1.0',
    'appInstallerId': 'myInstallerId'
});

6 - Also you can send Events to GA.

ga('send', 'screenview', {'screenName': 'Home'});
ga('send', 'event', 'video', 'started');

Hope this can help someone else!