declare local var.domainsegscount INTEGER;

if (!req.http.Fastly-FF && req.http.Cookie:_ga !~ "^GA"){

  set var.domainsegscount = std.strlen(regsuball(req.http.host, "[^\.]", ""));
  set var.domainsegscount += 1;

  add resp.http.set-cookie = "_ga=GA1." +
    var.domainsegscount + "." +
    randomint(1000000000, 2147483647) + "." +
    now.sec + ";" +
    "Domain=.fiddle.fastlydemo.net;" +
    "Max-Age=63072000;"
  ;

  # Prevent browser from caching a set-cookie
  set resp.http.cache-control:no-store = "";
}