Phonegap and Google Analytics are not working

冷暖自知 提交于 2019-12-11 18:58:36

问题


I'm building an app with phonegap and wanted to use Google Analytics. I installed this plugin with the CLI and implemented the following lines of code into my deviceReady event:

analytics.startTrackerWithId('UA-*******-5');
analytics.trackView('Frontsite');

(For sure I swapped the **** with my real tracking code).

Problem is I don't get an error, so I think the plugin works (or not), but the App is not tracked at all. When I go to the Google Analytics page where I created the mobile tracking property, it doesn't show my phone (or simulator) in the realtime-tab.


回答1:


No need to use plugin. You can directly call the google analytics API by using measurement protocol tracking id. It works fine in Andriod, IOS, Windows and Blackberry.

var dataform = {};
            dataform.v = 1;
            dataform.tid = "UA-xxxxxxxx-2";
            dataform.cid = "device id";
            dataform.t = "appview";
            dataform.an = "name";
            dataform.av = "0.0.1";
            dataform.cd = "Home Screen";
var url = "http://www.google-analytics.com/collect";
            $.ajax(url, {
                type: "post",
                contentType: "text/plain",
                data: dataform
            })
                    .done(function(result) {
                            alert("success");

                    })
                    .fail(function(error) {
                            alert("fail");

                    });


来源:https://stackoverflow.com/questions/24180238/phonegap-and-google-analytics-are-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!