1770 Posts in 495 Topics by 531 members
Blog Module
SilverStripe Forums » Blog Module » TinyMCE Strips onclick and other items
Discuss the Blog Module.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1054 Views |
-
TinyMCE Strips onclick and other items

10 August 2011 at 2:51am
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!
-
Re: TinyMCE Strips onclick and other items

10 August 2011 at 4:55am
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?
-
Re: TinyMCE Strips onclick and other items

10 August 2011 at 6:01am
I have heard that mentioned before. Any references I can look at on how to do this? Not proficient at js.
Thanks!
-
Re: TinyMCE Strips onclick and other items

10 August 2011 at 6:29am
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. -
Re: TinyMCE Strips onclick and other items

10 August 2011 at 7:31am
<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!!
-
Re: TinyMCE Strips onclick and other items

10 August 2011 at 8:00am
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.
| 1054 Views | ||
|
Page:
1
|
Go to Top |

