• Hi,

    I want to add a conversion tracker to a button on my WordPress posts page.

    Google Ads tells me to add the event snippet to the button image using something like:

    <img src=”download_button.gif” alt=”Download Whitepaper”
    width=”32″ height=”32″
    onclick=”return gtag_report_conversion(‘http://example.com/your-link&#8217;)” />

    (I replaced my URL).

    However, when I add the code “onclick=”return gtag_report_conversion(‘http://example.com/your-link&#8217;)” to the button image and click on Update in the posts menu, this code is always removed from in the text.

    Do you know why and how I can add this function call to my button image?

    Thanks,
    Paul

    • This topic was modified 6 years, 1 month ago by passiveinc.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Administrator accounts are typically the only ones with the unfiltered_html capability. Those that do not have it are subjected to the filters when saving, which strip out scripts and other security-related issues.
    If you are on multisite, the admin is not as capable as on a single WP site.
    You can use a plugin like Role Editor to make sure you have the capability, or a JS helper plugin to load the JS in the footer to attach the even to the button (it would need an ID).

    Thread Starter passiveinc

    (@passiveinc)

    Hi Joy,

    thank you for your answer.

    I am the owner of the website, so I should have all privileges. Do I have to change the capability?

    The described approach comes from Google Ads. So what would you recommend to attach the event snippet to the button? Using a plugin?

    Regards

    I should have all privileges

    “should” is the operative word here. I would use the plugin to find out if you do or not. Some other plugin could have changed things without you knowing it.
    If you do have the capability, then perhaps you have some plugin that is overzealously filtering the content.
    You can check this type of thing using Health Check plugin in Troubleshoot mode to disable plugins and theme for your user only and see if it happens with just core WP (but you have to verify you have the capability first).

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Event snippet code automatically removed from button image’ is closed to new replies.