Another option would be to use a Custom Javascript Macro to handle the custom variable. You could put your entire set custom variable ranking within it:
function(){
var url = {{referrer}}; //there is a GTM macro for the HTTP referrer
// confirm they came from G
if (url.indexOf("google.co") != -1 || url.indexOf("google.be") != -1 || url.indexOf("google.ie") != -1 || url.indexOf("google.fr") != -1) {
var urlVars = {};
var parts = url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) {
urlVars[key] = value;
});
// Return the Custom Variable value
return urlVars["cd"];
}
}
*Note, I didn't test this code, but it should be pretty close.
Then you can use that macro, you'd probably name it something like {{customVar1Val}} and plug that into Google Analytics tag: