I'm adding click tracking to an Umbraco v6.2 site so the client can track file downloads. When a button contains a link to a media library item I need to add an html attribute to ensure GA tracks these buttons.
The majority of the site is covered as most links are a "multi-link picker" datatype. However, a user can still add a link direct to the HTML via TinyMCE, which is not covered.
I've looked at replacing the link button in the TinyMCE editor with a custom plugin that adds the attributes I need, but this feels like a lot of work and limits us for future upgrades.
The other option is to manually update the HTML when a document is saved, adding an html attribute if the link contains "/media/???" which feels a little frail.
Umbraco adding attributes to HTML
Hi All,
I'm adding click tracking to an Umbraco v6.2 site so the client can track file downloads. When a button contains a link to a media library item I need to add an html attribute to ensure GA tracks these buttons.
The majority of the site is covered as most links are a "multi-link picker" datatype. However, a user can still add a link direct to the HTML via TinyMCE, which is not covered.
I've looked at replacing the link button in the TinyMCE editor with a custom plugin that adds the attributes I need, but this feels like a lot of work and limits us for future upgrades.
The other option is to manually update the HTML when a document is saved, adding an html attribute if the link contains "/media/???" which feels a little frail.
Does annyone have any better suggestions?
Hi James
What you could do is to parse the HTML of rich text editor at rendering time of a page rather than on save event of a document.
You could also create a helper that does the above and call it whenever you have an RTE to render.
In terms of parsing you could easily find all the links with regex library and add your custome attribute.
Please do let me know if you need a sample code to give you some idea ?
Cheers
Ali
Hi Ali,
Thanks for the quick reply.
Based on some further research, that's the simplest approach I have right now.
Within the AddGATrackingAttributes() extension I could then use the Html Agility pack to find the links.
However, this approach is basing on identifying the media library links simply by a URL, which doesn't feel very robust.
is working on a reply...