I need to provide a pageId on every URL however I don't need the user to see this pageId. For example
http://{domain}/{product-name}/{product-id}/{pageid} <-- I don't want to provide this
I have in my Global.asax:
routes.MapPageRoute("route-name", "path/{productName}/{product-id}", "~/ProductPage.aspx");
Is there some way to configure this route so it has a "hard coded" parameter page id for example something like this ---
routes.MapPageRoute("route-name", "path/{productName}/{product-id}", "~/ProductPage.aspx?pageid=1");
Is there some way to configure this route so it has a "hard coded"
parameter page id
Why yes... yes there is.
MapPageRoute has an overload that accepts a set of defaults for route values.
//Create route and set default values
routes.MapPageRoute(
"route-name",
"path/{productName}/{product-id}",
"~/ProductPage.aspx",
false,
new RouteValueDictionary{
{"product-id", 1}
});
So now if you hit this route without a "product-id" specified, it will always default to 1
Related
i'm from business and I would like to ask is it possible to create A/B test with dynamic part of URL?
API of backend application returns calculation ID for every visitor and its included on URL.
For example:
We have main URL www.example.pl and I want to create A/B test with redirect to dynamic URL:
www.example.com/calculation/(calculculation_id)
Is it possible?
If your goal is to redirect from https://www.example.com/product/laptop/12345
to https://www.example.com/product/laptop-test/12345 for each product and not for the product 12345.
Select test type redirect
Set up redirect rules for each variant
Customize your page targeting rules with "contains" or "starts with."
Customize your advanced redirection"
1.Set up redirect rules for each variant
Find in domain/path com/product
Replace with com/product-test
Add/modify query parameters/fragments (leave blank)
Original: https://www.example.com/product/laptop/12345
Redirect: https://www.example.com/product-test/laptop/12345 (see point 3.Customize your advanced redirection)
! Do not worry if you are entering the specific product 12345 this value seen by the system as variable xxxxx !
2.Customize your page targeting rules with "contains" or "starts with."
Modify the page targeting rules to ensure that we include any URL containing example.com/product.
3.Customize your advanced redirection.
In our example the text "com/product" is replaced with "com/product-test".
This is the site where you can find more information :
https://support.google.com/optimize/answer/6361119?hl=en
Yes, you can do that in different ways. I'd suggest using Feature Flags approach in your A/B test in order to have a flag to generated the dynamic next URL from the API.
I'll try to summarize in two steps that you should go:
Add a Javascript in the Optimize Visual Editor for. Example here. The idea is this script to add a new flag:
window.FeatureManager = window.FeatureManager || {};
window.FeatureManager.variant_1_to_change_the_url = true;
On your own script, look at this flag to call the backend API in order to get the calculated URL:
// in case of the variant 1
if (window.FeatureManager && window.FeatureManager.variant_1_to_change_the_url) {
// calls the API passing this flag to get the new URL
const redirectURL = fetch('my_endpoint', true/false); // true/false could be the variant verification
location.href = redirectURL; // this is a sample, you can change the URL however you want
} else {
// the original variation
}
Is there a way to get the previous page location before going to the next page in IronRouter?
Is there an event I can use to fetch this information?
Thanks in advance.
Since Iron Router uses the usual History API, you can just use the plain JS method:
history.go(-1);
or
history.back();
Edit: or to check the previous path without following it:
document.referrer;
You can achieve the behavior you want by using hooks.
// onStop hook is executed whenever we LEAVE a route
Router.onStop(function(){
// register the previous route location in a session variable
Session.set("previousLocationPath",this.location.path);
});
// onBeforeAction is executed before actually going to a new route
Router.onBeforeAction(function(){
// fetch the previous route
var previousLocationPath=Session.get("previousLocationPath");
// if we're coming from the home route, redirect to contact
// this is silly, just an example
if(previousLocationPath=="/"){
this.redirect("contact");
}
// else continue to the regular route we were heading to
this.next();
});
EDIT : this is using iron:router#1.0.0-pre1
Apologies for bumping an old thread but good to keep these things up to date saimeunt's answer above is now deprecated as this.location.path no longer exists in Iron Router so should resemble something like the below:
Router.onStop(function(){
Session.set("previousLocationPath",this.originalUrl || this.url);
});
Or if you have session JSON installed (see Session JSON)
Router.onStop(function(){
Session.setJSON("previousLocationPath",{originalUrl:this.originalUrl, params:{hash:this.params.hash, query:this.params.query}});
});
Only caveats with thisis that first page will always populate url fields (this.url and this.originalUrl there seems to be no difference between them) with full url (http://...) whilst every subsequent page only logs the relative domain i.e. /home without the root url unsure if this is intended behaviour or not from IR but it is currently a helpful way of determining if this was a first page load or not
I have the following rest structure for 'keyboard' objects:
GET /keyboards/ -> Lists user keyboards
POST /keyboards/ -> Creates new keyboard
GET /keyboards/{id} -> Get specific keyboard by id
PUT /keyboards/{id} -> Update specific keyboard by id
DELETE /keyboards/{id} -> Delete specific keyboard by id
The front end uses whatever keyboard is set to the users default keyboard, or, if the user has no custom keyboard set, simply returns a generic default.
At present, that is done by requesting another URL:
GET /keyboards/default
However, this appears a little misleading to me, as the resource 'default' could change whenever the user changes their default, and actually is a pointer to a different specific resource.
I'm not sure of a more elegant solution to this, as the front-end would appear to need to make two requests otherwise:
GET /keyboards/ -> Revealing the default
GET /keyboards/{id} -> To get the mappings associated with the keyboard
Which seems a more laborious, two step process. Is the first option a reasonable one, or am I missing a more elegant implementation?
It's OK to have convenience identifiers like 'default', 'latest' etc...
GET /keyboards/default
-> {
id: 3,
Another option is to hang the default keyboard off of a containing/referencing resource if there is one. For example
GET /computer
-> {
name: foo,
defaultKeyboard: 3,
...
If you want to avoid two requests you could have isDefault on the keyboard object.
GET /keyboards
[
{ id: 1, isDefault: false, ... }
{ id: 3, isDefault: true, ... }
That allows you to filter via querystring params.
Finally, this doesn't have to be an OR - you can have all of these for a convenient API for different access patterns.
Having to do a higher number of requests than with other architecture styles is a well-known and assumed drawback of RESTful APIs.
It is counterbalanced by the fact responses may be cached more easily as each resource has a unique URL.
Does you keyboard resource expose an "IsDefault" property? It should. And so:
GET /keyboards/
Would return a list of keyboards. You could examine the keyboard resources in the list and choose the one that is the default.
And you could also solve this by making this a query parameter:
GET /keyboards?IsDefault=true
There's nothing wrong with having a convenience /keyboards/default identifier, as long as its cacheability is being defined correctly, which in this case would probably be to tell clients to not cache it at all.
In my Synfony2 wep application, there is two different role that the same user can have. He can whether be an employee or a boss. So, I want to have a switch button the change role so the user have a different view on data. For example, has a Boss the user would see the progress of the work in a project and as a Employee he would see the work to be done from each member of the team in the same project. So basically, the boss would have privilege on some action and the employee on some others.
How should I do the switch between the roles? I was planning to have two different url for each roles /boss/todesand employee/todos. In some case, I would use the same twigs template (e.g. the listing of the todos). How do I do when I need to generate a URL such as /boss/todos/{id} by always specifying the same route_name path('todo_show', {'id': id}).
I think it is pretty similar to the _locale parameter. Is it possible to create a custom parameter similar to _locale in Symfony 2.3?
Thanks in advance !
IMO you think too complex. Create one route for both users, say /todo/{id} which will redirect user based on their role to the user specific route /boss/todo/{id} or /employee/todo/{id}.
setting a default parameter in your routing config file is not enought?
todo_show:
pattern: /{_user}/todos/{id}
defaults: { _controller: YourAppBundle:Default:getTodos, _user: boss }
requirements:
_user: boss|employee
methods: [GET]
and then:
path('todo_show', {'id': id, '_user': 'employee'}); // for boss there is no need to specify _user
The situation
I'd like to use GA to track some serverside operations. That's why I cant make use of the GA JavaScript functions. But, as you might know, you can request the utm.gif right from your server. This already works fine.
The Problem
I'd like to trackt custom parameters. But I have no idea how to add them in the right format to the url-request
This one should do the custom parms. But I didn't get any results in GA.
utme=5(Init*load_success*http://www.mydomain.de)8(userstatus)9(fan)11(2)
Full list of params:
ref ts
utmac UA-XXXXXX-5
utmcc __utma=186215409.1789216404.1265552708.1280074861.1280493144.21;+__utmz=;
utmcs ISO-8859-1
utmdt Button
utme 5(Init*load_success*http://www.mydomain.de)8(mycustomvar)9(mycustomvalue)11(2)
utmfl -
utmhn mydomain.de
utmje -
utmn 1114675642
utmp button
utmr http://www.mydomain.de
utmsc -
utmsr -
utmul de-de
utmwv 4.5.7
not sure what's going wrong, given what you posted, but how about you write out what you want to send the traditional way (with javascript) and put it on a test page. Use firebug or whatever to grab the requested url that's built and compare it to what you have now.
The value of the utme gif Request parameter is encoded by ga.js--it's the only one that is, as far as i know.
Calling __trackEvent is the usual way to set the value of utme. These are client-side events though, which is no doubt why you are trying to set utme directly.
So if you just want to bind 5(Initload_successhttp://www.mydomain.de)8(userstatus)9(fan)11(2) to the variable utme, and you can't rely on user-behavior to trigger that binding, then here's what i suggest:
Pack your data into a 'custom variable' scoped to the page--this way, when the __trackPageview() is called, the value will be set.
Here's the analytics code required in your HTML to implement that:
The method signature for a custom variable:
pageTracker._setCustomVar(slot, // integer between 1 and 5, inclusive (just use '1')
name, // user-defined name for the custom variable
value, // string representing the value for the custom variable
scope, // you want '3' for page-level (an int, not a string though)
);
Within the HTML (order matter, of course):
pageTracker.__setCustomvar(1, "A Name", "A Value", 3);
pageTracker.__trackPageview();
A key point here is that the parameter 'value' can be set dynamically, so for the 'value' parameter, i guess you want to pass in 5(Initload_successhttp://www.mydomain.de)8(userstatus)9(fan)11(2)
Finally, here are the two key sources (Implementation Guide, Usage Guide) on Custom Variables from the GA Team