Tracking Textbox Entries with Google Analytics

Druida

New Member
I am trying to capture in google analytics the data that is entered into a textbox. The code that I have so far is below, I am trying to capture the data by Javascript, but I can't seem to get it to work. The CMS Platform I am using is sitecore. \[code\]<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SalesRepSearch.ascx.cs" Inherits="USEndoscopy.Website.layouts.USEndoscopy.Sublayouts.SalesRepSearch" %><%@ Import Namespace="USEndoscopy.Library.Search" %><script type="text/javascript"> var textbox = document.getElementById('txtZipCode'), submitButton = document.getElementById('btnSalesRepSearch');submitButton.onClick = function () { _trackEvent('data-store', textbox.name, textbox.value, 0); // 'data-store' can be replaced with whatever category of data you want, for sortability's sake // the 0 can be replaced with any other numerical data you want - but it must be numerical}</script><p></p><p> <asp:Panel DefaultButton="btnSalesRepSearch" runat="server"> <asp:TextBox ID="txtZipCode" runat="server" Width="300px"></asp:TextBox> <asp:Button ID="btnSalesRepSearch" runat="server" CssClass="buttonregular" Text="Search" OnClick="btnSalesRepSearch_Click" /> <asp:RequiredFieldValidator ID="reqTxtZipCode" runat="server" ValidationGroup="ZipCode" ControlToValidate="txtZipCode" Display="Dynamic" ErrorMessage="Please enter a valid US Zip code" CssClass="error"></asp:RequiredFieldValidator> <asp:RegularExpressionValidator ID="regExTxtZipCode" runat="server" ValidationExpression="^\d {5}(-\d{4})?$" ValidationGroup="ZipCode" ControlToValidate="txtZipCode" Display="Dynamic" ErrorMessage="Please enter a valid US Zip code" CssClass="error"></asp:RegularExpressionValidator> </asp:Panel></p><p> <asp:Repeater ID="salesRepContainer" runat="server"> <ItemTemplate> <%# ((SalesRep)Container.DataItem).RepName %><br /> <%# ((SalesRep)Container.DataItem).Phone %><br /> <a href="mailto:<%# ((SalesRep)Container.DataItem).Email %>"><%# ((SalesRep) Container.DataItem).Email %></a><br /> </ItemTemplate> </asp:Repeater></p><p> <sc:Text Field="InternationalMessage" runat="server" /></p>\[/code\]
 
Back
Top