Last active
December 29, 2015 10:09
-
-
Save barryokane/7654967 to your computer and use it in GitHub Desktop.
Google Analytics Cross domain tracking when using server side redirect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="C#" %> | |
<script runat="server"> | |
protected void RedirectClick(object sender, CommandEventArgs e) | |
{ | |
if (Page.IsValid) | |
{ | |
string url = RedirectUrl.Value; | |
//... whatever else ... | |
Response.Redirect(url); | |
} | |
} | |
</script> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title></title> | |
<script type="text/javascript"> | |
var _gaq = _gaq || []; | |
//...YOUR ASYNC GOOGLE ANYLTICS CODE HERE ... | |
function AppendGA() { | |
var tracker = _gaq._getAsyncTracker('rollup'); | |
$("#<%= RedirectUrl.ClientID %>").val(tracker._getLinkerUrl($("#<%= RedirectUrl.ClientID %>").val())); | |
} | |
</script> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
... other form controls including buttons with different server side events .. | |
<div> | |
...controls relevant to a server side redirect ... | |
<asp:HiddenField ID="RedirectUrl" Value="http://test.com" runat="server" /> | |
<asp:Button ID="submit" runat="server" Text="Redirect Event" OnCommand="RedirectClick" ValidationGroup="Group2" OnClientClick="AppendGA()"></asp:Button> | |
</div> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment