Google Analytics Plugin Not Reporting Users in Dashboard - angularjs

I am trying to add Google Analytics to my app. I am using Dan Wilson's Google Analytics plugin. I am not getting any errors but my Google Analytics Dashboard is not Updating at all. Where am i wrong,
var googleanalyticsApp = angular.module('starter', ['ionic','ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
if(typeof analytics !== undefined) {
analytics.startTrackerWithId("UA-872489XX-1");
console.log("Analytics Initialized");
} else {
console.log("Google Analytics Unavailable");
}
});
});
googleanalyticsApp.controller('ExampleController', function($scope,$cordovaGoogleAnalytics) {
function _waitForAnalytics(){
if(typeof analytics !== 'undefined'){
analytics.startTrackerWithId("UA-872489XX-1");
analytics.trackView('APP first screen');
console.log("Analytics in Controller");
}
else{
setTimeout(function(){
_waitForAnalytics();
},250);
}
};
_waitForAnalytics();
I have initialized the Google Analytics in both Device Ready and Controller.
Console.log states as:
But my Dashboard is not updating at all
Kindly, help me out.

Your dashboard is pointing at Nov 14 - Nov 14. Change this to the current day, it defaults to the previous day.
It can take up to 24 hours for data to appear in Analytics console. Also why do you have different naming conventions when calling analytics functions? You can change 'analytics' to $cordovaGoogleAnalytics in your code.

You need to set trakid In app.js platform ready like following -
$ionicPlatform.ready(function() {
if(typeof analytics !== undefined) {
analytics.startTrackerWithId("UA-872489XX-1"); // set your trakId
console.log("Analytics Initialized");
} else {
console.log("Google Analytics Unavailable");
}
});
})
If above won't work use following -
$ionicPlatform.ready(function() {
if(window.ga != undefined) {
window.ga.startTrackerWithId("UA-872489XX-1");
} else {
console.log("Google Analytics Unavailable");
}
})
Then in each controller just set view like following -
googleanalyticsApp.controller('ExampleController', function($scope,$cordovaGoogleAnalytics) {
// Here no need to wait to load analytics as already loaded
analytics.trackView('APP first screen');
})

Related

Google Analytics don't show page view title

I'm using google-analytics-plugin to connect google analytics with ionic 1.
In app.js,
/* Google Analytics */
if(typeof analytics !== undefined) {
analytics.startTrackerWithId("UA-XXXXXXXXX-X");
console.log("Connected Google Analytics");
} else {
console.log("Google Analytics Unavailable");
}
In controller.js, I couldn't call 'analytics' directly, so I called 'eventListener'.
.controller('LoginCtrl', function($scope) {
document.addEventListener("deviceready", function () {
if(typeof analytics !== undefined) {
analytics.trackView("Login");
}
}, false);
}
.controller('PlaylistsCtrl', function($scope) {
document.addEventListener("deviceready", function () {
if(typeof analytics !== undefined) {
analytics.trackView("PlaylistsCtrl");
}
}, false);
}
It connected to GoogleAnalytics but don't show the pageview title. Count is increased but show two controllers as a same page.
Can anyone please tell me what should I fix to show pageview title ?
Thanks in advance!
Try to use the following to show the page title
window.ga.trackView(pagename);

Ionic App Onesignal Push Notification not able to redirect to specific page

I am trying to redirect to a specific job page when there's a new applicant.
Here's the code:
app.run(function($ionicPlatform, $location) {
$ionicPlatform.ready(function() {
if (ionic.Platform.isWebView()) {
window.plugins.OneSignal
.startInit("xxxxxxxxxxxxxx", "xxxxxxxxxxxx")
.handleNotificationReceived(function(jsonData) {
console.log("/app/upcoming/" + jsonData.payload.additionalData.url);
$location.path("/app/upcoming/" + jsonData.payload.additionalData.url);
})
.endInit();
}
The console shows the correct address but it does not redirect or have any errors.
For Ionic you will need to use $state.go to redirect the user to a different page in your app.
var notificationOpenedCallback = function(result) {
var data = result.notification.payload.additionalData;
if (data && data.targetUrl) {
var state = $injector.get($state);
state.go(data.targetUrl);
}
};
window.plugins.OneSignal
.startInit("YOUR_APPID", "YOUR_GOOGLE_PROJECT_NUMBER_IF_ANDROID")
.handleNotificationOpened(notificationOpenedCallback)
.endInit();

interstitial ad don't show up (AngularJs)

my app.js :
$ionicPlatform.ready(function() {
var admobid = {};
// select the right Ad Id according to platform
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
interstitial: 'ca-app-pub-3940256099942544/1033173712'
};
} else {
admobid = { // for Windows Phone
interstitial: 'ca-app-pub-3940256099942544/1033173712'
};
}
if(window.AdMob) AdMob.prepareInterstitial({
adId:admobid.interstitial,
isTesting:true,
autoShow:false
});
my controller.js :
.controller('ChatsCtrl', function($scope, Chats) {
$scope.$on('$ionicView.beforeEnter', function(e) {
if (window.AdMob) AdMob.showInterstitial();
});
$scope.$on('$ionicView.beforeLeave', function(e) {
if (window.AdMob) AdMob.showInterstitial();
});
})
I'm building an ionic framework app for android and i need to add it a interstitial ad, it should run whenever user enters chats tab.
Here is my code, i copied most part of it from http://pointdeveloper.com/how-to-add-interstitial-ads-on-navigation-to-ionic-framework-apps/ .
I changed interstitial: 'ca-app-pub-3940256099942544/1033173712' parts with my own key but it didn't work. Where is the problem?
(I'm testing it in both my android phone(Nexus 5) and Genymotion android emulator)
The internal life cicle for interstitial ads when requestInterstitialAd is called is the following one, you can read more here: https://github.com/appfeel/admob-google-cordova/wiki/requestInterstitialAd
requestInterstitialAd();
options.autoShowInterstitial == true ? showInterstitial : raise(admob.events.onAdLoaded)
So if you have set options.autoShowInterstitial = true, then it should be automatically shown, otherwiese, you should call admob.requestInterstitialAd and wait for admob.events.onAdLoaded with atType === 'interstitial' to be raised. Then you should do something like:
document.addEventListener(admob.events.onAdLoaded, function (e) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
admob.showInterstitialAd();
}
});

admobpro AdMob.showInterstitial() causes infinite loop

admobpro AdMob.showInterstitial() causes infinite loop
I am using admobpro in an ionic/angularjs app, and every time i call AdMob.showInterstitial() I get an advertisement to appear, but when i click the X to close the advertisement a new one instantly pops up. I was initally calling the showInterstitial from the init function but thought maybe this was the problem, so i created a test page that would show the interstitial when i clicked a button, the same
result. infinite loop.
has anyone else had this problem.
var admobid = {};
// select the right Ad Id according to platform
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
banner: 'ca-app-pub-6869992474017983/9375997553',
interstitial: 'ca-app-pub-6869992474017983/1657046752'
};
} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
admobid = { // for iOS
banner: 'ca-app-pub-6869992474017983/4806197152',
interstitial: 'ca-app-pub-6869992474017983/7563979554'
};
} else {
admobid = { // for Windows Phone
banner: 'ca-app-pub-6869992474017983/8878394753',
interstitial: 'ca-app-pub-6869992474017983/1355127956'
};
}
function adSetter(){
if(window.AdMob) AdMob.createBanner( {
isTesting:true,
adId:admobid.banner,
position:AdMob.AD_POSITION.BOTTOM_CENTER,
autoShow:true} );
if(window.AdMob) AdMob.prepareInterstitial( {adId:admobid.interstitial, autoShow:false} );
}
function onDeviceReady(){
adSetter();
}
function domLoaded(){
document.addEventListener("deviceready", onDeviceReady, false);
}
my code:
fron ionic
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleLightContent();
}
//start admob
domLoaded();
//end admob
});
})
i see you have mixed a bit of the code. the $ionicPlatform.ready() of ionic is called when the deviceready of cordova has occured so no need to call the device ready again inside the $ionicPlatform.ready()
i have a complete demo for ionic ads here http://pointdeveloper.com/how-to-add-banner-ads-to-ionic-apps-using-admob-pro-plugin/
From the code it seems ok and it should run the only thing that you have to make sure is that the AdMob.showInterstitial() is not being called in a loop.
As you mentioned you also tried it with a button, i suggest you create a fresh project and try again.

How to get AdMob Pro working in Ionic

I am getting 'AdMob' is undefined when I try to execute the code below. I am trying to use the Cordova AdMob Pro plugin, but can't get past the undefined error(s). I can't confirm if the plugin is even being loaded.
Here are the versions I'm using: AngularJS v1.3.4, Cordova v4.1.2, Ionic v1.2.8. I'm running the code on a Galaxy S5 phone running Android version 4.4.4.
I've tried adding this code in both the app.js and the controller.
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
console.log('window.cordova.plugins: ' + window.cordova.plugins); //returns object
console.log('window.cordova.plugins.AdMob: ' + window.cordova.plugins.AdMob); //returns undefined
console.log('window.AdMob: ' + window.AdMob); //returns undefined
console.log('AdMob: ' + AdMob); //returns undefined
console.log('window.AdmobAd: ' + window.AdmobAd); //returns undefined
console.log('AdmobAd: ' + AdmobAd); //returns undefined
if (window.AdMob || AdMob) {
alert('admob plugin found');
var admob_key = (device.platform == "Android") ? "ADMOB_KEY" : "IOS_PUBLISHER_KEY";
var admob = window.AdMob;
admob.createBannerView(
{
'publisherId': admob_key,
'adSize': admob.AD_SIZE.BANNER,
'bannerAtTop': false
},
function () {
admob.requestAd(
{ 'isTesting': false },
function () {
admob.showAd(true);
},
function () { console.log('failed to request ad'); }
);
},
function () { console.log('failed to create banner view'); }
);
}
});
Just went through this as well and found that the error is from trying to find 'AdMob' when that doesnt exist on if (window.AdMob || AdMob)
if you just use 'if (window.AdMob) {' you should be fine.
I just developed an AngularJS extension on top of AdMob Pro so you can interact better with this Cordova Plugin.
Here is the repository: https://github.com/santonocito/angular-admobpro
Here an example of how you can use it with Ionic:
angular.module('yourApp', ['ionic', 'admob'])
.run(function($rootScope, $state, $log, $adMob) {
$ionicPlatform.ready(function() {
// AdMob
if(window.AdMob) {
var admobid;
if (device.platform == "Android") {
admobid = { // for Android
banner: 'ca-app-pub-your-ad-key',
interstitial: 'ca-app-pub-your-ad-key'
};
} else {
admobid = { // for iOS
banner: 'ca-app-pub-your-ad-key',
interstitial: 'ca-app-pub-your-ad-key'
};
}
$adMob.createBanner( {
adId: admobid.banner,
autoShow: true,
bgColor: 'black',
position: $adMob.position.BOTTOM_CENTER
});
$adMob.prepareInterstitial({
adId: admobid.interstitial,
autoShow: false
});
}
});
});
1.install admob phonegap plugin
cordova plugin add admob
init admob plugin,init plugin after deviceready event
admob.initAdmob("admob banner ID","admob interstitial ID");
3.show admob ads
admob.showBanner(admob.BannerSize.BANNER,admob.Position.TOP_APP);//show banner at the top of app
ref:https://github.com/admob-google/admob-cordova

Resources