0

I am look for a solution to this

I am trying to track an event in Google analytics using the onclick event but I need to pass a dynamic variable to the url field Please see below code

  <asp:hyperlink ID="Hyperlink2" runat="server" Font-Size="8pt" 
  NavigateUrl='<%# Eval("URL") %>' 
  Target="_blank" CssClass="flatorange" 
  style="margin-bottom:10px;" 
  onclick="ga('send', 'event', '<%# Eval("URL") %>');">Apply Now</asp:hyperlink>
  <br />    

1 Answer 1

0

An event has four required parameters and you're only passing three.

Should be (at a minimum):

ga('send', 'event', '<%# Eval("URL")%>', 'event action');

More info on Events here - Event Tracking.

3
  • I tried that, it looks like the issue is with the dynamic variable if I replace it with an actual label, it works, just cant insert it dynamically onclick="ga('send', 'event','Testcategory', 'Click', '<%# Eval("URL")%>');" Jan 27, 2014 at 18:27
  • Can you share the site at all? Do you see any errors firing onclick? Try removing the single quotes?
    – Blexy
    Jan 27, 2014 at 18:45
  • the page doesn't load at all, gives me a parse error, referencing the line when I add the dynamic variable into the ga code. Tried removing the single quotes, same error, There should be a way to bypass hardcoded values Jan 27, 2014 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.