我一直试图通过Android和iOS让Google Analytics在PhoneGap 1.2.0中运行。
在PhoneGap 1.2.0中使用Google Analytics时Android和iOS之间的主要区别是什么?
答案 0 :(得分:12)
所需的三个主要组件以及Android和iOS的不同部分。
GAP-alytics
Google Analytics
PhoneGap
<plugin name="GoogleAnalyticsTracker" value="com.package.path.to.class.GoogleAnalyticsTracker"/>
添加到res / xml / plugins.xml文件注意:请记住,即使iOS和Android版本有phonegap-1.2.0.js
个文件,它们也是不相同的文件。代码是不同的,您不能只在平台之间复制它。确保您的应用使用适当的版本。
Android Javascript
window.plugins.googleAnalytics.start ("your UA code", //UA-account ID
function() { console.log("started") }, //successCallBack
function() { console.log("didn't start") } //failureCallBack
);
window.plugins.googleAnalytics.trackPageView ( //**NB**: NOTE CAPITAL 'V'
"/Main Page", //Page (include /)
function() {console.log("tracked page view")}, //successCallBack
function() {console.log("didn't track page view")} //failureCallBack
);
window.plugins.googleAnalytics.trackEvent (
"Contact", //Category
"Email", //Action
“John Smith”, //Label
0, //Value
function() { console.log("tracked event") }, //successCallBack
function() { console.log("didn't track event") } //failureCallBack
);
iOS Javascript
window.plugins.googleAnalyticsPlugin.startTrackerWithAccountID(“your UA code”);
window.plugins.googleAnalyticsPlugin.trackPageview(whichPage); //Note lowercase v in trackPageview.
window.plugins.googleAnalyticsPlugin. googleAnalytics.trackEvent(
"Contact",
"Email",
“John Smith”
0,
function() { console.log("tracked event") }, //successCallBack
function() { console.log("didn't track event") } //failureCallBack
);
<强> NB 即可。变量'whichpage'必须以forwardslash(/)开头。没有这个,Android会让你离开。 iOS不会。