Jump to:

1835 Posts in 1139 Topics by 554 members

Blog Module

SilverStripe Forums » Blog Module » TinyMCE Strips onclick and other items

Discuss the Blog Module.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1528 Views
  • Hello_electro
    Avatar
    Community Member
    80 Posts

    TinyMCE Strips onclick and other items Link to this post

    Hi All:

    I need to use Google Analytics to track outbound links in my blog posts. I am having a really hard time trying to figure out the right way to get TinyMce to stop removing code I am adding via the html option.

    I found a couple related topics in the forum, but nothing seemed to pan out when I tried and the posts were related to rather old versions.

    Has anyone had to use the onclick in their links for google outbound tracking? Any insight would be greatly appreciated!

    thank you!

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: TinyMCE Strips onclick and other items Link to this post

    If you need to add that kind of stuff then TinyMCE really isn't the best tool for the job. Is there no way you can add the click handlers from an external script automatically instead of trying to add them via TinyMCE?

  • Hello_electro
    Avatar
    Community Member
    80 Posts

    Re: TinyMCE Strips onclick and other items Link to this post

    I have heard that mentioned before. Any references I can look at on how to do this? Not proficient at js.

    Thanks!

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: TinyMCE Strips onclick and other items Link to this post

    I've never done this for google. Is the code you need to add always the same or does it differ?
    If you want to ease your way into js I recommend looking at jquery.

  • Hello_electro
    Avatar
    Community Member
    80 Posts

    Re: TinyMCE Strips onclick and other items Link to this post

    <a href="http://www.example.com" onClick="recordOutboundLink(this, 'Outbound Links', 'example.com');return false;"> </code]

    for the most part it is the same. The example.com i believe can be anything you want. i believe that is what is reported back to google to identify the link to you in analytics.

    I read something about using the rel attribute and applying that in the tinymce and having jquery add in the above onclick code. Again, not totally understanding of jquery/javascript makes me need to do some more research!!

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: TinyMCE Strips onclick and other items Link to this post

    Ok if you get jquery you can do this:
    First of all, put this code in your main Page.ss file before the closing body tag.

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript">
    function recordOutboundLink(link, category, action) {
    try {
    var pageTracker=_gat._getTracker("UA-XXXXX-X");
    pageTracker._trackEvent(category, action);
    setTimeout('document.location = "' + link.href + '"', 100)
    }catch(err){}
    }
    $("#YourContentArea a").click(function(event) {
    event.preventDefault();
    recordOutboundLink(this, 'Outbound Links', this.href);
    });
    </script>

    Make sure you put in your own analytics code in there. Also #YourContentArea needs to be replaced with either the id or the class of the place where the content from the TinyMCE editor ends up on your page.

    1528 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.