问题
Intending to Use the ADBPhoneGap Plugin to implement the Adobe Analytics in my mobile App. Following is the code , i am trying along with the basic configurations asked to do in the Link. The error i am getting is Can't read the Property 'ADB' of the Undefined. How to fix the issue. Also not able to figure out what and where to implement the 'Lifecycle Metrics Auto Tracking' mentioned in the above link. Can anyone help with the basic script for trackState or trackAction method , with reference to the following example .
<!DOCTYPE HTML>
<html>
<head>
<!-- <meta name="viewport" content="width=320; user-scalable=no" /> -->
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>PhoneGap</title>
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title">
<script type="text/javascript" charset="utf-8" src="cordova-2.3.0.js"></script>
<script type="text/javascript" charset="utf-8" src="ADB_Helper.js"></script>
<script type="text/javascript">
var ADB;
function initialize() {
alert('In initalize');
document.addEventListener("deviceready", onDeviceReady, true);
//alert('Device Ready');
alert('Exit initalize');
}
function onDeviceReady() {
alert('in On Device Ready method');
ADB = window.plugins.ADB;
alert('Exit On Device Ready method'+ADB);
// Note: A request for permission is REQUIRED by google. You probably want to do this just once, though, and remember the answer for subsequent runs.
navigator.notification.confirm('GA_PLUGIN would like your permission to collect usage data. No personal or user identifiable data will be collected.', permissionCallback, 'Attention', 'Allow,Deny');
}
function TrackButtonClicked()
{
alert('Track Button Entry');
// ADB.trackState("login page", {"user":"john","remember":"true"});
alert('Track Button Exit');
}
</script>
</head>
<body onload="initialize();" id="stage" class="theme"> <!-- onunload="goingAway();" -->
<h1>Test Adobe Analytics Plugin</h1>
<div class="space"></div>
<div>
<a href="#" class="btn large" onclick="TrackButtonClicked();">Track Event</a>
<!--<a href="#" class="btn large" onclick="VariableButtonClicked();">Track Event with Variable</a>
<a href="#" class="btn large" onclick="PageButtonClicked();">Track Page</a>-->
</div>
</body>
</html>
回答1:
Since in ADBHelper.js variable called ADB is already declared, it seems that you are overwriting it two times in your code. First you shadow it with the
var ADB
on your global scope, which practically means overwriting it. Then you do
ADB = window.plugins.ADB;
which again sets it as window.plugins.ADB which seems to be undefined.
So remove this two lines, after that, if the plugin is correctly installed, the ADB should already be object containing the methods for Adobe Analytics.
来源:https://stackoverflow.com/questions/27821704/cant-read-property-abd-of-the-undefined-adobe-analytics-phonegap-plugin