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:

  1. Sign in to Google Analytics.

  2. Click Admin from the menu bar at the top of the page.

  3. From the dropdown menus, select an account and a property to which you want to add custom dimensions.

  4. Under the Property column, click Custom Definitions, then click Custom Dimensions.

  5. Click New Custom Dimension.

  6. 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.

  7. 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.

  8. 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.

  9. 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
    }
?>