Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Blog Module

Discuss the Blog Module.

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

TinyMCE Strips onclick and other items


Reply

6 Posts   1802 Views

Avatar
Hello_electro

10 August 2011 at 2:51am Community Member, 80 Posts

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!

Avatar
MarcusDalgren

10 August 2011 at 4:55am Community Member, 288 Posts

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?

Avatar
Hello_electro

10 August 2011 at 6:01am Community Member, 80 Posts

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

Thanks!

Avatar
MarcusDalgren

10 August 2011 at 6:29am Community Member, 288 Posts

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.

Avatar
Hello_electro

10 August 2011 at 7:31am Community Member, 80 Posts

<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!!

Avatar
MarcusDalgren

10 August 2011 at 8:00am Community Member, 288 Posts

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.