Get Adobe DTM to work with page load rules in Angular - angularjs

Basically, I'm trying to find a way to efficiently fire tags using Adobe DTM in Angular without having to change the page. We have an exceptionally long elevation cycle so having to add _satelitte.track() to a page to get a new tag to fire would severly limit the benefit of using DTM. I'm primarily concerned this would be necessary in the case that I'd want to only fire tags in certain situations so I wouldn't be able to use the already existing rule in place.
I believe that _satellite.pageBottom() is what tells the satellite object that a page load has occured. I'm attempting to call _satellite.pageBottom() to mimic a page load any time the route changes.
.config(function($routeProvider, $httpProvider){
$routeProvider.when('/one', {
templateUrl: 'view1.html',
controller: 'Data1Controller'
}).when('/two', {
templateUrl: 'view2.html',
controller: 'Data2Controller'
}).when('/three', {
templateUrl: 'view1.html',
controller: 'Data3Controller'
}).when('/four', {
templateUrl: 'view2.html',
controller: 'Data4Controller'
}).when('/five', {
templateUrl: 'form.html',
controller: 'FormController'
}).otherwise({
controller: "Default",
templateUrl: 'default.html'
});
$httpProvider.interceptors.push('CacheBusterInterceptor');
}).run(function($rootScope){
$rootScope.$on('$routeChangeStart', function(){
_satellite.pageBottom();
});
});
This has worked well for me in other situations where I want to mock a page load but it's not working with the _satellite.pageBottom() call and I am at a loss how I might get DTM to work in Angular without using the direct call rules. Any advice on getting either this way to work or another work around to having to make changes to the code on the page?
Thanks,
Mike

I've used a generic _satellite.track('pageLoad') direct call rule to work around single page app challenges. You don't have to change the page code that way. As long as the variables you need are accessible by DTM, you can run all your logic in the tag manager.
Edit for dynamic direct call rule:
$rootScope.$on('$routeChangeSuccess',function(e, curr, pre){
_satellite.track(current.$$route.originalPath);
})
or if you want to add a pagename in your $routeProvider config:
$routeProvider.when('/',{pageName:'Fantastic Home Page',controller:...,templateUrl:...}
$rootScope.$on('$routeChangeSuccess',function(e, curr, pre){
_satellite.track(current.pageName || 'whoops no pageName');
})

Adobe DTM allows for firing rules based on popstate or hashtag change. The best approach is to setup your rules based on these events and if your app supports deep linking then also setup page load rules based on the deep link URL's.

Related

AngularJS Route : set several parameters values for the same route

I was wondering if it was possible with AngularJS to do something like this :
I currently have a route with a first parameter called 'resource' that can be "device" or "group". There is a second parameter called 'id' but it doesn't matter. With the following code the route accepts anything as first parameter :
.when("/templates/:resource/:id", {
templateUrl: "/templates/views/navigation/templates.html",
controller: 'ctrlTemplates',
tab: "templates",
})
It makes me check in the controller if the value of the first parameter is either 'device' or 'group'. I would like to get rid of this verification part without creating two routes if possible :
.when("/templates/group/:id", {
templateUrl: "/templates/views/navigation/templates.html",
controller: 'ctrlTemplates',
tab: "templates",
})
.when("/templates/device/:id", {
templateUrl: "/templates/views/navigation/templates.html",
controller: 'ctrlTemplates',
tab: "templates",
})
So my question is, is it possible, using ONE route, to have several urls ? Something like this for instance :
.when("/templates/('device'|'group')/:id", {
templateUrl: "/templates/views/navigation/templates.html",
controller: 'ctrlTemplates',
tab: "templates",
})
So I don't have to check the value of the parameter afterwards in the controller myself using
if([('group', 'device'].includes($routeParams.resource))...
Do you know if it's possible ? Or a similar way to do it?
Best regards,
You can't do what you want. If you want to use ui-router you can pull it off but AngularJS ngRoute does not give you the ability to use regexes, or bind route parameters to types. If you are willing to switch to ui-router I can give you an example of how to do what you want.
I am willing to switch to ui-router if it can help me achieve what I want to do.
Also, if it supports types it's nice as I have parameters that must be integers. I am going to have a look at some examples.
If you have any example with regexes It would be nice !

Ionic Angular routeprovider not working

I'm working on an Ionic App where i run in some trouble.
I'm new to AngularJS and Ionic.
The user needs to be logged in to use the app. To check this an apicall to my server is called on entry of the app. If the user is not logged in, the app will show a modal where the user can login.
But in the small second that the apicall is made you see the "inside" of the app (restricted pages).
To avoid this i want to place a screen where the app checks if the user is logged in. And if the user is logged in, the screen needs to send the user further in the app.
The problem in this is that the app doesn't send the user on. I replaced all the code with a simple a href (ui-sref) but that doesn't work either.
The funny, weird part is that if i run it in my browser it works. But on my mobile(android) is doesn't do anything.
I tried it with a function with $location.path but i doesn't send me anywhere. It does set the path.
I tried $apply, $digest, $window.location.href .... etc etc. none worked.
If i don't use the wait screen everything works fine.
wait.html
<a ui-sref='app.proposals({"favorite" : 0})'>Continue</a>
RouteProvider
matcher.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider)
{
$ionicConfigProvider.tabs.position("bottom");
$ionicConfigProvider.tabs.style("standard");
$stateProvider
.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'AppCtrl'
})
.state('app.proposals', {
url: '/proposals/:favorite',
views: {
'menuContent': {
templateUrl: 'templates/proposals.html',
controller: 'ProposalsCtrl'
}
}
})
.state('app.proposal', {
url: '/proposal/:title/:id/:url',
views: {
'menuContent' : {
templateUrl: 'templates/proposal.html',
controller: 'ProposalCtrl'
}
}
})
.state('wait',{
url: '/wait',
templateUrl: 'templates/wait.html',
controller: 'WaitCtrl'
});
// if none of the above states are matched, use this as the fallback
//$urlRouterProvider.otherwise('/app/proposals/0');
$urlRouterProvider.otherwise('/wait');
});
Alright, now, the best way to solve this would be use a better practice. Your application follows the standard Authentication Flow. Now, according to me, wouldn't it be better if you just animate the current view in context. This will serve two purposes
reduce the render-load time;
get rid of you problem.
According to me, the problem here is that when you make the API call, Ionic tries to get hold of a cached page. The best way to fix it to have a default base check; point to index.html, the IndexController checks is the user is logged in, if it is, use $state.go("STATE_NAME") to go to the logged in state, otherwise, go to a state where you login.
Trust me when I say this: not only will this be easier, it'll also be more maintainable once the application code really builds up.
Should you require any further clarifications and/or code samples, just comment here. I haven't included them as it's trivial and extrapolates the logic and the syntax you're already familiar with.

dynamic routing in ui-router in angularjs and change the url

I write an application with angularjs and use ui router for dynamic routing , my app has a page for display list of news and when click on a news , Explanation of the news is showing
for example if I have a news with id=3 when i click on link of this news the url change to news/3 and when click on a news with id=5 url change to news/4 but i want to change url to news/subnews/third or news/subnews/fifth
my piece of code for change url and content is like this
.state('news', {
abstract:true ,
url: "/news",
templateUrl: "views/news/news.html",
})
.state('news.showAll', {
url: "",
templateUrl: "views/news/showAllNews.html",
})
.state( 'news.detail',{
url:"/:newsId",
templateUrl: "views/news/tmpShowDet.html",
controller:"newsShowing",
resolve:{
newsId: ['$stateParams', function($stateParams,newsId){
return $stateParams.newsId;
}]
}
})
what is the true way for display like news/subnews/....
How many 'subnews' do you want?
Translating numbers to words can get a little tricky, and spoken-language specific. Example: at 'subnews/101' do you want 'subnews/onehundredandone or subnews/onehundredandfirst or subnews/oneohone'.
I would recommend, if you only have a few subnews possibilities, going by categories.In that case, it seems you already know how to implement, or have access to the documentation for UrlRouteProvider.
If you have many subnews, I would leave the parameter as an integer, which is relatively spoken-language agnostic. You can always mask it or build a lookup table, etc if you don't want it displayed.
Speaking of which, if you still want to change the integer to a word, just use a lookup, and the url docs.
Cheers, bro

AngularJS: multiple edit forms routing?

I have a listing of Requests each with a Request_Type_Id which maps to a feeder list (which could grow as the application evolves). For example, we might have (id, request_type) 1 - Sales Information, 2 - Technical Support, 3 - Order Information and, of course, each one has unique fields so the edit forms are very different.
By clicking the name, I want to open the correct of these different edit forms.
For routing, I have this:
$routeProvider
.when('/editrequest/:req_id/:id', {
controller: 'EditRequestController',
templateUrl: '/App/Views/editRequest.html'
}).otherwise( { redirectTo: '/' } );
because I set the edit link to
{{req.title}}
I am still trying to learn AngularJS and am wondering if the best way to proceed from here would be to choose the correct edit form on /App/Views/editRequest.html by using ng-show. This would mean there would be at least 3 forms on that template (not nested, though) which might be problems in some browsers.
Is there a more AngularJS way to do this that I haven't learned yet?
Thanks in advance!
templateUrl can be a string or a function, which accepts route parameters and return a string.
In your case, you can doing so:
$routeProvider
.when('/editrequest/:req_id/:id', {
controller: 'EditRequestController',
templateUrl: function(params) {
// use params.req_id to generate a url
return '/App/Views/editRequest'+params.req_id+'.html';
}
}).otherwise( { redirectTo: '/' } );
Another important thing worth mention here is, be careful when use interpolate in href or src. Use ng-href or ng-src instead.

Confused in how to implement tab based app with angular ui-router (like gmail)

I was thinking last night about how to port our crud application to a tab based app, like gmail. First, reading a lot about ui-router, i thought in create a tabService that will create a new tab for each state change (listen $rootScope.stateChangeSuccess), the new tab would include the corresponding view (ui-view="bancos") that will display the state template.
My first test and my first problem, when shown the list of items, a click over one of the item (itemId=4 for example) should open a new tab and display the item with id=4 in this tab, inside the corresponding (ui-view="bancos/4"). Note how i'm trying to map named ui-view with states to display the state defined templates in the corresponding ui-view.
I know that ui-router sample seems to do what i'm trying, but they are using nested states with unamed ui-view inside parent state template. In my case, the parent state ui-view element and his child state ui-view element should be sibling.
Considering the nature of angular, tree structured, and the nature of ui-router states, tree structured too, can i use ui-router to implement my requirements (crud application with tab based design).
Regards
Danny
Here is me example, if you have questions i can answer
http://plnkr.co/edit/tqfPVFaesSe9Q6ZkPMzE?p=preview
Short explain: don't use tabs instead of that create a fake, works well and you save a lot of work.
Best
I was looking for the same info, does the following example help you?http://plnkr.co/edit/gMsKK9l7J0B8vZIMIVfD?p=preview (Not my coding.)
Edit:
I've found more useful data.
https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views
In my code, I have set it up like this:
.state('surveys.list', {
url: '/list',
templateUrl: "survey/surveys_overview.tpl.html",
controller: 'SurveyOverview'
})
.state('surveys.create', {
abstract: true,
templateUrl: "survey/survey.create.tpl.html",
controller: 'SurveyManageController'
})
.state('surveys.create.views', {
url: '/create',
views: {
'details': {
templateUrl: "survey/survey.create.details.tpl.html"
},
'steps': {
templateUrl: "survey/survey.create.steps.tpl.html"
}
}
});
The surveys.create.tpl.html just has a and two tabs with each one div:
<div ui-view="details"> & <div ui-view="steps">

Resources