I’m new to Angular and I’m creating a project with Ionic and I want to implement Flurry with it.
Everything looks fine except for my setUserId function. I have the following Service based on this tutorial (https://github.com/lakshaydulani/ionic1-flurry-marketplugin):
.service('flurryService', function () {
// create a new instance
this.init = function () {
var options = {
logLevel: 'DEBUG', // (VERBOSE, DEBUG, INFO, WARN, ERROR)
enableLogging: true, // defaults to false
enableEventLogging: true, // should every event show up the app's log, defaults to true
enableCrashReporting: true, // should app crashes be recorded in flurry, defaults to false, iOS only
enableBackgroundSessions: true, // should the session continue when the app is the background, defaults to false, iOS only
reportSessionsOnClose: true, // should data be pushed to flurry when the app closes, defaults to true, iOS only
reportSessionsOnPause: true // should data be pushed to flurry when the app is paused, defaults to true, iOS only
}
// workaround - create a blank flurryAnalytics for development site since FlurryAnalytics will be available on devices only
if (window.cordova)
this.flurryAnalytics = new FlurryAnalytics();
else
this.flurryAnalytics = {
logEvent: function () {}, init: function () {}, logError: function(a,b){console.error(a,b);}
};
if(ionic.Platform.isAndroid()){
flurry_id = 'MYFLURRYID';
} else { //iOS
flurry_id = 'MYFLURRYID';
}
this.flurryAnalytics.init(flurry_id, options, function () {}, function (err) {});
};
this.logEvent = function (title, obj) {
if(this.flurryAnalytics)
this.flurryAnalytics.logEvent(title, obj, function () {}, function () {});
};
this.logError = function (title, error) {
if(this.flurryAnalytics)
this.flurryAnalytics.logError(title, error, function () {}, function (err) {});
};
// PS I created this function
this.setUserId = function (id) {
if(this.flurryAnalytics)
this.flurryAnalytics.setUserId(id, function () {}, function (err) {});
};
})
Inside my login page I injected flurryService and tried to call setUserId function after the login is checked. This is just a simplified example.
.controller('homeCtrl', function($scope, $http, flurryService) {
$scope.login = function (){
encodedata=JSON.stringify({
"email": email,
"password": password});
$http({
method : 'POST',
url : '/login',
data : encodedata
})
.success(function(data) {
var result = data.split('|');
var user_id = result[1];
flurryService.setUserId(user_id);
});
};
})
The problem is that I’m getting the following error:
services.js:34 TypeError: this.flurryAnalytics.setUserId is not a function
Line 34 is this one:
logEvent: function () {}, init: function () {}, logError: function(a,b){console.error(a,b);}
Does anyone know what is the problem?
Thanks