All Collections
PHP and Javascript Node Examples
PHP Nodes
Routing multiple geos using a PHP node
Routing multiple geos using a PHP node

How to create conditions using a PHP node for easier management of routing

Zeno avatar
Written by Zeno
Updated over a week ago

Our condition nodes let you return a yes or no route.

But what if you want to route many countries to different paths? It can be annoying to chain "If Canada" to "If France" to "If Australia" and so on to give the routing you want.

An easier way to do this is using a singular PHP node and a switch statement to describe what routes users should go to.


With PHP nodes, the code just needs to return the number value of the connection at some point. So if it executes "return 1", the code will stop executing and send the user down the "On Done 1" route.

Here's an example of how you can use this to route users based on country code to multiple different routes:

<?php

$country_code = '{location-countrycode}';

// route geos to different ON DONE connectors
switch ($country_code) {
case 'US';case 'CA';case 'GB';case 'NZ';case 'AU':
return 2;
break;
case 'DE':
return 3;
break;
case 'FR':
return 4;
break;
default:
return 1; //default route is always 1
}

?>

Here we do the following:

  • Set $country_code to the token {location-countrycode}. With PHP nodes, tokens will process before anything else, so this value can then be used in later code. You can use any FunnelFlux token.

  • We create a "switch" statement based on the value of $country_code

  • If the value is US, CA, GB, NZ or AU, we go down the On Done 2 connector

  • If its DE, we go down route 3

  • If its FR, we go down route 4

  • If its none of these, we go down route 1 (you always need a default).

You can use this approach for any token value and its great for collapsing many conditions into a single node.

You can also connect the On Done X connectors to rotators, to route users to sets of pages, giving you fine control over everything.

If you use our heatmaps for understanding EPV and ROI of nodes, this approach can also make it easier to split your traffic and analyse it.

Happy tracking!

Did this answer your question?