title: Set Custom Dimension in measurement pool in Google Analytics
body: <p>I need to set a Custom Dimension from the server side, I am trying this request: </p>
  
  <p><a href="http://www.google-analytics.com/collect?&amp;v=1&amp;tid=UA-XXXXXXXX-X&amp;cid=111111111.111111111&amp;t=all&amp;cd1=MyCustomDimension" rel="nofollow">http://www.google-analytics.com/collect?&amp;v=1&amp;tid=UA-XXXXXXXX-X&amp;cid=111111111.111111111&amp;t=all&amp;cd1=MyCustomDimension</a></p>
  
  <p>In the "t" value I also try "event" and "pageview" but it doesn't work.</p>
  
  <p>I created this class for do the request.</p>
  
  <pre><code>public static class GoogleAnalyticsServerSide
  {
      private static string googleURL = "http://www.google-analytics.com/collect";
      private static string googleVersion = "1";
      private static string googleTrackingID = "UA-XXXXXX-X";
      private static string googleClientID = "111111111.11111111";
  
      private static Dictionary&lt;string, string&gt; baseValues()
      {
          Dictionary&lt;string, string&gt; data = new Dictionary&lt;string, string&gt;();
          data.Add("v", googleVersion);         // Version.
          data.Add("tid", googleTrackingID);    // Tracking ID / Web property / Property ID.
          data.Add("cid", googleClientID);      // Anonymous Client ID.
          return data;
      }
      public static void TrackEvent(string category, string action, string label)
      {
          Dictionary&lt;string, string&gt; postData = new Dictionary&lt;string, string&gt;();
          postData = baseValues();
          postData.Add("t", "event");
          postData.Add("ec", category);
          postData.Add("ea", action);
          postData.Add("el", label);
          Track(postData);
      }
  
      public static void TrackCustomDimension(string index, string value)
      {
          Dictionary&lt;string, string&gt; postData = new Dictionary&lt;string, string&gt;();
          postData = baseValues();
          postData.Add("t", "all");
          postData.Add("cd" + index, value);
          Track(postData);
      }
      private static void Track(Dictionary&lt;string, string&gt; postData)
      {
          try
          {
              var request = (HttpWebRequest)WebRequest.Create(googleURL);
              request.Method = "POST";
  
              var postDataString = postData
                  .Aggregate("", (data, next) =&gt; string.Format("{0}&amp;{1}={2}", data, next.Key,
                                                               HttpUtility.UrlEncode(next.Value)))
                  .TrimEnd('&amp;');
  
              // set the Content-Length header to the correct value
              request.ContentLength = Encoding.UTF8.GetByteCount(postDataString);
  
              // write the request body to the request
              using (var writer = new StreamWriter(request.GetRequestStream()))
              {
                  writer.Write(postDataString);
              }
  
              try
              {
                  var webResponse = (HttpWebResponse)request.GetResponse();
                  if (webResponse.StatusCode != HttpStatusCode.OK)
                  {
                      throw new HttpException((int)webResponse.StatusCode,
                                              "Google Analytics tracking did not return OK 200");
                  }
              }
              catch (Exception ex)
              {
  
              }
          }
          catch (Exception e)
          {
  
          }
      }
  
  }
  </code></pre>
  
  <p>The class works well because if I use the <code>TrackEvent</code> method it works. I am not sure if I missing something in the post request of Custom Dimension.</p>
  
  <p>Thanks in advance.</p>