Home>Support>OnClick Code for Google Analytics

OnClick Code for Google Analytics

By MelH, 6 years ago. Last reply by MelH, 6 years ago.

Hello,

I am trying to put the following code into the onclick-section of a button:
ga(‘send’, ‘event’, ‘Button’, ‘Klick’, ‘SADownload’, ‘1’);

Unfortunately, this does not work. When I view the source code it looks like this:
onclick=”ga(‘send’, ‘event’, ‘Button’, ‘Klick’, ‘SADownload’, ‘1’);”

It seems to add a backslash to the single quotation marks. How can I prevent this from happening?

Thanks in advance!

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 6 years, 8 months ago Alex S
    Hi, I Work Here

    Hi Mel,

    The code should work regardless of the slashes (they’re being added for security reasons). Do you have a public URL where we can take a look at what’s going on? Also, would it be possible for you to send me an export of your button widget? To do this please open up the page that contains the button in the editor and click the Layout button in the Page Builder toolbar. Then click import/export and then click download. Please upload the export to a 3rd party file hosting site such as teknik.io.

  2. 6 years, 8 months ago MelH

    Hi Alex,

    thanks for your response!
    This is the URL: https://bitco3.com/en/topics/self-assessment/ (the button ist “Download it now! both at the top and on the bottom”)
    This is the URL to the export: https://u.teknik.io/buvIq.json

  3. 6 years, 8 months ago Alex S
    Hi, I Work Here

    Hi MelH,

    Thanks. The provided layout appears to work without issue. To clarify, does the event click show in Google Analytics real-time view?

  4. 6 years, 8 months ago MelH

    Hi Alex,

    good to know. Unfortunately it neither shows in the real-time view nor in the overview of the last few days although I clicked it multiple times. I thought it was due to the backslashes that are added during the conversion.

  5. 6 years, 8 months ago Alex S
    Hi, I Work Here

    Hi Mel,

    To confirm, are you able to see other events on your page? I ask because I just want to confirm Google Analytics is working on your website.

  6. 6 years, 8 months ago MelH

    Hi Alex,

    I can see the stats about website clicks, users, etc. As this is the first conversion I try to track I cannot say whether conversions are being tracked. Yet, the other data works fine.

  7. 6 years, 8 months ago Alex S
    Hi, I Work Here

    Hi Mel,

    Hm. What happens if you change the onclick to the following?

    ga("send", "event", "Button", "Klick", "SADownload", "1");
    
  8. 6 years, 8 months ago MelH

    Hi Alex,

    now it works! It’s magic :)

    Thank you so much for your great support. I really appreciate it!

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More