I'm new to titanium, I want to integrate google analytics module in my project. I'm trying thisti.googleanalytics
Step 1: I've successfully imported modules using gittio.
Step 2: I've copied the analytics.xml and changed the tracking id to mine.
Step 3: <?xml version="1.0" encoding="utf-8" ?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="TypographyDashes"> <!--Replace placeholder ID with your tracking ID--> <string name="ga_trackingId"><< Paste my tracking id >></string>
<!--Enable automatic activity tracking-->
<bool name="ga_autoActivityTracking">true</bool>
<!--Enable automatic exception tracking-->
<bool name="ga_reportUncaughtExceptions">true</bool>
</resources>
Step 4: Added Internet Permission: <android xmlns:android="http://schemas.android.com/apk/res/android"> <manifest> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> </manifest> </android>
Step 5: Pasted the sample code into my project index.js file as below.
// TODO: Replace the below tracking ID with your own from Google Analytics. var GoogleAnalytics = require('ti.googleanalytics'), tracker = GoogleAnalytics.getTracker('<I've paste my trackid here>'), /Fields = GoogleAnalytics.getFields(),/ MapBuilder = GoogleAnalytics.getMapBuilder();
var win = Ti.UI.createWindow({ backgroundColor: '#fff' }); win.addEventListener('open', function(evt) { tracker.send( MapBuilder .createAppView() .set(Fields.SCREEN_NAME, 'home') .build() ); });
var button = Ti.UI.createButton({ title: 'Track Click' }); button.addEventListener('click', function() { tracker.send( MapBuilder .createEvent('ui_action', 'button_press', 'send_button', null) .build() ); }); win.add(button); win.open();
But, I'm getting error Googleanalytics has no method 'getFields', Kindly help me out to resolve this issue. Thanks in advance!.
[ERROR] : TiExceptionHandler: (main) [3982,3982] ----- Titanium Javascript Runtime Error ----- [ERROR] : TiExceptionHandler: (main) [0,3982] - In alloy/controllers/index.js:33,69 [ERROR] : TiExceptionHandler: (main) [0,3982] - Message: Uncaught TypeError: Object #<Googleanalytics> has no method 'getFields' [ERROR] : TiExceptionHandler: (main) [0,3982] - Source: ogleAnalytics.getTracker("UA-65734282-1"), Fields = GoogleAnalytics.getFields( [ERROR] : V8Exception: Exception occurred at alloy/controllers/index.js:33: Uncaught TypeError: Object #<Googleanalytics> has no method 'getFields' [INFO] : APSAnalyticsService: Stopping Analytics Service [INFO] : GAV4: Thread[GAThread,5,main]: No campaign data found. [INFO] : APSAnalyticsService: Analytics Service Started [INFO] : APSAnalyticsService: Stopping Analytics Service