Google Analytics for custom URL parameters
You can set up Custom Dimensions in Google Analytics. First, I would recommend upgrading to Universal Analytics then do the following:
Sign in to Google Analytics.
Click Admin from the menu bar at the top of the page.
From the dropdown menus, select an account and a property to which you want to add custom dimensions.
Under the Property column, click Custom Definitions, then click Custom Dimensions.
Click New Custom Dimension.
Add a Name. This can be any string, but use something unique so it's not confused with any other dimension or metric in your reports.
Select the Scope. Choose to track at the Hit, Session, User, or Product level. Read more about scope and how custom dimensions are processed in our Developer Guide.
Check the Active box to start collecting data and see the dimension in your reports right away. To create the dimension but have it remain inactive, uncheck the box.
Click Create.
Once you have your Custom Dimension created, you can use this function to send the hit to Google Analytics. This example uses PHP and you would need to create a Custom Dimension called ref
.
<?php
if(isset($_GET['ref']))
{ ?>
<script>
ga('send', 'pageview', {'ref': '<?php echo $_GET["ref"]; ?>'});
</script>
<?php
}
?>