PhoneGap GA插件不工作 [英] Phonegap GA plugin not working
问题描述
我使用phonegap 3.3在本地构建Android应用程序并尝试使用GA插件
我已使用
$安装了GAplugin b $ b
phonegap本地插件添加https://github.com/phonegap-build/GAPlugin.git
在索引中添加了此代码。
var gaPlugin;
document.addEventListener(deviceready,onDeviceReady,false);
function onDeviceReady(){
alert(calling ga);
gaPlugin = window.plugins.gaPlugin;
alert(calling init)
gaPlugin.init(successHandler,errorHandler,UA-48220634-1,1);
gaPlugin.trackPage(nativePluginResultHandler,nativePluginErrorHandler,index.html);
gaPlugin.trackEvent(nativePluginResultHandler,nativePluginErrorHandler,Button,Click,event only,1);
gaPlugin.exit(nativePluginResultHandler,nativePluginErrorHandler);
}
function successHandler()
{
alert(init success);
}
function errorHandler()
{
alert(init failed);
}
function nativePluginResultHandler()
{
alert(tracking success);
}
function nativePluginErrorHandler()
{
alert(tracking failed);
}
我获得所有成功的邮件,但在Google Analytics >
我也尝试手动包括GAPlugin.js但没有改变。
我可以在插件列表中看到GAPlugin
Anujs-MacBook-Pro:my-app edunewz $ phonegap plugin list
[phonegap] com.adobe.plugins.GAPlugin
[phonegap] com.jamiestarke.webviewdebug
[phonegap] org.apache.cordova.camera
[phonegap] org.apache.cordova.file
[phonegap] org.apache .cordova.file-transfer
[phonegap] org.apache.cordova.inappbrowser
任何人帮助我。
进入/platforms/android/AndroidManifest.xml,并确保
< uses-permission android:name =android.permission.INTERNET/>
< uses-permission android:name =android.permission.ACCESS_NETWORK_STATE/>
< uses-permission android:name =android.permission.ACCESS_COARSE_LOCATION/>
< uses-permission android:name =android.permission.ACCESS_FINE_LOCATION/>
执行: / p>
phonegap本地插件add https://github.com/phonegap-build/GAPlugin.git
phonegap local plugin add https://github.com/apache/cordova-plugin-network-information.git
phonegap local plugin add https://github.com/apache/cordova-plugin-geolocation.git
code>
我也添加了:
< gap:plugin name =com.adobe.plugins.gaplugin/>
< gap:plugin name =NetworkStatusvalue =org.apache.cordova.NetworkManager/>
< gap:plugin name =Geolocationvalue =org.apache.cordova.GeoBroker/>
到config.xml。
请务必将/plugins/com.adobe.plugins.GAPlugin/www中的GAPlugin.js复制并粘贴到/ www文件夹中。
以下代码来源于: a href =https://github.com/shanabus/phonegapbuildtest/blob/master/Index.html =nofollow> https://github.com/shanabus/phonegapbuildtest/blob/master/Index.html
大部分只是额外的,因为他在实际应用中显示工作反馈。
< script src =GAPlugin.js>< / script>
< script type =text / javascriptcharset =utf-8>
// var baseUrl ='http://grappsmobile.com/grtv/';
$(function(){
//退出时
// gaPlugin.exit(nativePluginResultHandler,nativePluginErrorHandler);
}
var gaPlugin;
document.addEventListener(deviceready,myDeviceReadyListener,false);
function myDeviceReadyListener(){
gaPlugin = window.plugins.gaPlugin;
gaPlugin.init(gaSuccess,gaError,UA-23823097-4,10);
// 23823097-4< - web property
// 23823097-3< - app property
}
function gaSuccess(){
try
{
gaPlugin.trackPage(nativePluginResultHandler,nativePluginErrorHandler,index.html);
$(#gaResults)。html(< span class ='success'> GA tracked pageview!< / span>);
$(#pageHome ul li a)。on(click,function(){
gaPlugin.trackPage(nativePluginResultHandler,nativePluginErrorHandler,$(this).attr (href));
});
} catch(e){
$(#gaResults)。html(< span class ='error'> GA无法跟踪网页浏览 - + e +< / span> ;);
}
}
函数gaError(){
$(#gaResults)。append(< span class ='error'> GA error< ; / span>);
}
function nativePluginResultHandler(obj){
$(#gaResults)。append(< br />< span class ='warn'> GA Plugin Result - );
if(obj!= undefined){
$(#gaResults)。append(obj);
}
$(#gaResults)。append(< / span>);
}
function nativePluginErrorHandler(){
$(#gaResults)。append(< span class ='error'> GA插件错误结果< / span> ;);
}
< / script>
确保您使用的是移动应用分析,而不是上述代码中的网络分析
观察他是如何跟踪这些事件的(我从中学到很多东西):
https://github.com/shanabus/phonegapbuildtest/search?q=gaPlugin.trackEvent
使用插件的示例来完成VariableButtonClicked,PageButtonClicked,TrackButtonClicked。 https://github.com/bobeast/GAPlugin/blob/master/Example /index.html 示例代码从来没有用于我,所以只是用它作为参考。
检查 https://www.google.com/analytics/web/?hl=zh_CN#realtime/ 并祈祷。有时在显示之前需要很长时间,所以请在开始排除故障之前给出一天。其余的分析数据是24小时后,所以选择当天,如果你想看到数据后1-5个小时..有时更长。
有些人可能说这些额外的步骤是overkill,他们会是正确的..但我不得不做一些组合之前,它为我工作。奇怪的是,我觉得我要离开的东西。祝你好运!
I am using phonegap 3.3 to build android app locally and trying to use the GA plugin
I have installed the GAplugin using
phonegap local plugin add https://github.com/phonegap-build/GAPlugin.git
Added this code in my index.
var gaPlugin;
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("calling ga");
gaPlugin = window.plugins.gaPlugin;
alert("calling init")
gaPlugin.init(successHandler, errorHandler, "UA-48220634-1", 1);
gaPlugin.trackPage( nativePluginResultHandler, nativePluginErrorHandler, "index.html");
gaPlugin.trackEvent( nativePluginResultHandler, nativePluginErrorHandler, "Button", "Click", "event only", 1);
gaPlugin.exit(nativePluginResultHandler, nativePluginErrorHandler);
}
function successHandler()
{
alert("init success");
}
function errorHandler()
{
alert("init failed");
}
function nativePluginResultHandler()
{
alert("tracking success");
}
function nativePluginErrorHandler()
{
alert("tracking failed");
}
I get all successful messages but cant see anything in Google Analytics.
I also tried manually including the GAPlugin.js but no change.
I can see GAPlugin in list of plugins
Anujs-MacBook-Pro:my-app edunewz$ phonegap plugin list
[phonegap] com.adobe.plugins.GAPlugin
[phonegap] com.jamiestarke.webviewdebug
[phonegap] org.apache.cordova.camera
[phonegap] org.apache.cordova.file
[phonegap] org.apache.cordova.file-transfer
[phonegap] org.apache.cordova.inappbrowser
Can anybody help me out.
解决方案 Go into /platforms/android/AndroidManifest.xml and make sure
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
are present.
Execute:
phonegap local plugin add https://github.com/phonegap-build/GAPlugin.git
phonegap local plugin add https://github.com/apache/cordova-plugin-network-information.git
phonegap local plugin add https://github.com/apache/cordova-plugin-geolocation.git
I also added:
<gap:plugin name="com.adobe.plugins.gaplugin" />
<gap:plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager" />
<gap:plugin name="Geolocation" value="org.apache.cordova.GeoBroker" />
to config.xml.
Make sure you copy + paste GAPlugin.js from /plugins/com.adobe.plugins.GAPlugin/www into your /www folder.
The code posted below comes from: https://github.com/shanabus/phonegapbuildtest/blob/master/Index.html
Most of it is just extra, as he shows working feedback in the actual app.
<script src="GAPlugin.js"></script>
<script type="text/javascript" charset="utf-8">
//var baseUrl = 'http://grappsmobile.com/grtv/';
$(function() {
// on exit
// gaPlugin.exit(nativePluginResultHandler, nativePluginErrorHandler);
});
var gaPlugin;
document.addEventListener("deviceready", myDeviceReadyListener, false);
function myDeviceReadyListener() {
gaPlugin = window.plugins.gaPlugin;
gaPlugin.init(gaSuccess, gaError, "UA-23823097-4", 10);
//23823097-4 <-- web property
//23823097-3 <-- app property
}
function gaSuccess() {
try
{
gaPlugin.trackPage( nativePluginResultHandler, nativePluginErrorHandler, "index.html");
$("#gaResults").html("<span class='success'>GA tracked pageview!</span>");
$("#pageHome ul li a").off("click").on("click", function() {
gaPlugin.trackPage( nativePluginResultHandler, nativePluginErrorHandler, $(this).attr("href") );
});
} catch (e) {
$("#gaResults").html("<span class='error'>GA could not track pageview - " + e + "</span>");
}
}
function gaError() {
$("#gaResults").append("<span class='error'>GA error</span>");
}
function nativePluginResultHandler(obj) {
$("#gaResults").append("<br /><span class='warn'>GA Plugin Result - ");
if (obj != undefined) {
$("#gaResults").append(obj);
}
$("#gaResults").append("</span>");
}
function nativePluginErrorHandler() {
$("#gaResults").append("<span class='error'>GA Plugin Error Result</span>");
}
</script>
Make sure you're using Mobile App Analytics, and not web analytics like he is in the above code snippet.
Observe how he is tracking these events (I learned a lot from this):
https://github.com/shanabus/phonegapbuildtest/search?q=gaPlugin.trackEvent
Use the plugin's example for how to accomplish VariableButtonClicked, PageButtonClicked, TrackButtonClicked. https://github.com/bobeast/GAPlugin/blob/master/Example/index.html The example code never worked out of the box for me, so just use it as a reference.
Check under https://www.google.com/analytics/web/?hl=en#realtime/ and pray. Sometimes it takes a long time before showing, so give it a day before you start troubleshooting. The rest of analytics data is like 24 hours behind, so select the current day if you want to see data 1-5 hours after.. sometimes longer.
Some people might say these extra steps are overkill, and they would be right.. but I had to do some combination of all of them before it worked for me. Strangely enough I feel like I'm leaving something out. Good luck!
这篇关于PhoneGap GA插件不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!