+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Google Analytics and library item hyperlinks

Google Analytics and library item hyperlinks

2 posts, 0 answered
  1. Kevin Pipher
    Kevin Pipher avatar
    91 posts
    Registered:
    30 Nov 2005
    15 Sep 2010
    Link to this post
    Hi,

    I'm interested in using Google Analytics to track downloads of documents within the Library module. I know that using analytics, I must insert an onclick javascript event into the hyperlink (reference).

    Is there a way to modify the Generic Content editor dialog for inserting library links, so that the hyperlink is modified correctly with the onclick event?

    Ie. when a user is editing a generic content control on a page, and clicks the insert document icon, once they select a document from a library and return to the generic content editor window, the hyperlink markup would be modified from:
    <a href="/Libraries/MyLibrary/SomeDocument.sflb.ashx" shref="[Sitefinity]...">My link</a>
    to:
    <a href="/Libraries/JFY_Communities/Pesticides_Use_Lit_Review.sflb.ashx" shref="[Sitefinity]..." onClick="javascript: pageTracker._trackPageview('"javascript: pageTracker._trackPageview('/Libraries/MyLibrary/SomeDocument.sflb.ashx'); ">My link</a>

    I've read the forum article on extending the downloadlist control here, but it doesn't quite apply to the generic content control and the library dialog.

    Any info anyone could supply would be greatly appreciated!

    Thanks,
    Kevin.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    16 Sep 2010
    Link to this post
    Hi Kevin Pipher,

    Modify Sitefinity\Admin\ControlTemplates\Libraries\Dialogs\DocumentEditorDialog.ascx and its insertLink() function as shown below

    function insertLink()
        {
            var closeArgument = currentElement;
            selValue = document.getElementById('<%= selectedValueField.ClientID %>')
            editHolder = document.getElementById('<%= editHolder.ClientID %>');
            titleField = document.getElementById('<%= titleTxt.ClientID %>');
            targetLink = document.getElementById('<%= Target.ClientID %>');
            var uplImg = document.getElementById('<%= uploadedDocument.ClientID %>');
            closeArgument.href = selValue.value;
            closeArgument.innerHTML = titleField.value;
            if (targetLink.checked) {
                closeArgument.setAttribute("target", "_blank");
     
            }
            if (selValue.value.indexOf("~/") == 0) {
                closeArgument.setAttribute("sfref", selValue.value);
            }
            else if (selectedItem != undefined && selectedItem.unresolved) {
                 closeArgument.setAttribute("sfref", selectedItem.unresolved);
                 closeArgument.setAttribute("onclick", "javascript: pageTracker._trackPageview('" + selValue.value + "');");
            } else if (uplImg != undefined && uplImg.attributes["sfref"] != undefined) {
                closeArgument.setAttribute("sfref", uplImg.attributes["sfref"].value);
            } else {
                closeArgument.removeAttribute("sfref");
            }
     
            if (getRadWindow()) {
                var radWindow = getRadWindow();
                radWindow.argument = closeArgument;
                radWindow.close(closeArgument);
            }
        }

    this will add on click event and google tracking.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered