Hi all
I’ve been building Modx websites using the Evo branch for a little while and have been trying to figure out the best way to build a page redirect that takes a link and processes it before directing the user to the correct merchant page. The function of this redirect page is to add additional tracking information to the link such as the search engine source or some kind of tracking code so assist the Pay Per Click campaigns as well as add js based goal monitoring scripts.
I have throught of three ways to do this and wouldnt mind someone giving me some pointers (especially implementation 3 at the bottom):
idea 1 - external script - my first implementation was external to modx where i have a equivalent/mapped link put into the TV such as "jmpTo.php?link=1". "link=1" would be the link that is static in the script which I would add tracking bits by doing some string manipulation in the jmpTo.php script. So I would have a setup such as :
*product page in modx*
eg niceCup product page
- (tv1) jmpTo.php?link=1
- (tv2) jmpTo.php?link=2
*jmpto.php*
cut down version of whats in he redirect page
//decide whats the outbound link
switch ($_get['link']){
case '1' :
$outLink = 'www.myfavemugs.com/prod/123';
break;
case '2' :
$outlink = 'www.myfavemugs.com/prod/456';
breakl
}
//do some processing of the outbound link before redirting the user
$url = addSomeTrackingInfoAndLogClick($outLink);
//$url would be something like www.myfavemugs.com/prod/123?src=goo&trck=ppc1
header( 'Location: '.$url ) ;
*template*
<a href="[*tv1*]">product 1</a>
idea 2 - all modx hacky solution - document that takes the doc id and tv-name to redirect - As before I would have a page with one or more merchant links. Each TV actually holds the outbound link. I would put in the actual merchant links into each TV and have a separate Modx document called "linkTo". I would in the "linkTo" page template have a snippet that takes the doc id [*id*] and the corresponding tv to get the TV content holding the outbound link then do the prcoessing within a snippet to redirect the linkTo page. In the actual template of the page I would have the links as "linkTo?pg=[*id*]&tv=tvNameOfOutboundlink"
*product page in modx*
eg niceCup product page
- (tv1) www.myfavemugs.com/prod/123
- (tv2) www.myfavemugs.com/prod/456
*template of the product page*
A link would look like this.
< a href="linkTo?pg=[*id*]&tv=tv1"> Product 1</a>
Note: it is intentional I have hard coded "tv1" above
*snippet used in linkTo*
The code I have written in linkTo takes the [*id*] and using the name of the tv (as in the example above "tv1") I can get the outbound link this can then be processed in the same way as the function addSomeTrackingInfoAndLogClick($outLink) above
idea 3 - create a special TV type - I’ve been trying to work out whether its possible to create a new TV that pretty much does all of idea 2 for me. So the user would put in the link in the tv on the page as before (in idea 2) but instead of having to create hacky link in the template (like "linkTo?pg=[*id*]&tv=tv1") they can just put in the tv name. This would then automaitcally on rendering the page replace the link with the neccessary modx redirect page link eg linkTo?pg=40&tv=tv1, where 40 is the doc id and tv1 is name of the tv which hold the outbound link.
the actual question
I realised i just type quite a verbose explanation! Sorry!
My question : is idea 3 possible and if so what hook or modification should I look at? Or can someone point me in the right direction if I am off track with my solution to the problem? just to re-iterate, the ultimate aim of idea 3 is to create a special TV type that can create the redirect page link for me.