Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • James Gaisford 22 posts 165 karma points
    Oct 09, 2014 @ 11:28
    James Gaisford
    0

    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?

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Oct 09, 2014 @ 12:12
    Ali Sheikh Taheri
    0

    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

  • James Gaisford 22 posts 165 karma points
    Oct 09, 2014 @ 12:26
    James Gaisford
    0

    Hi Ali,

    Thanks for the quick reply.

    Based on some further research, that's the simplest approach I have right now.

    PromoFooterBody = new HtmlString(content.GetPropertyValue<string>("promoFooterBody"));
    PromoFooterBody.AddGATrackingAttributes()
    

    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.

Please Sign in or register to post replies

Write your reply to:

Draft