Forum Discussion

benpiddington's avatar
11 years ago

Adding web analytics to email templates

Hi,

 

We're looking at adding web tracking to our Lithium email templates, in particular the @mentions template.
We first tried adding the tracking code as a parameter to the end of the ${notification.message.webUi.url} variable, but this broke the anchor when users received the email.

 

Has anyone else had any experience in adding web analytics to the email templates and have used a better method? Or is there a way to perform string manipulation on these URL's so that we could place the parameter before the message anchor in the URL?

 

Any advice would be very helpful.

 

thank you!

Ben

  • DougS's avatar
    DougS
    Khoros Oracle

    Hi Ben,

     

    Can you elaborate on how this broke the anchor tag on your email templates?  Our email templates use Apache Velocity, so you can add variables, conditionals, etc.  Not having seen exactly how the template broke, I've added a simple logic block that might be used (I haven't QAed this, so it might have a bug or 2 in the code) to append to the URL:

     

    #set ($my_web_tracking_number = "13483648732823w648")
    #set ($notif_url = $notification.message.webUi.url)
    #set ($fragment = "")
    #if ($notif_url.contains("#"))
      #set ($fragment = $notif_url.substring($notif_url.indexOf("#"), $notif_url.length() -1))
      #set ($notif_url = $notif_url.substring(0, $notif_url.indexOf("#")))
    #end
    #if ($notif_url.contains("?"))
      #set ($notif_url = $notif_url + "&" + $my_web_tracking_number + $fragment)
    #else
       #set ($notif_url = $notif_url + "?" + $my_web_tracking_number + $fragment)
    #end

     

    Hopefully that example helps.  Here is a link to the velocity user guide page, which may help as a reference:

     

    https://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html

     

    -Doug

    • Hi Doug.

      Thank you very much for getting back to me. We were adding the parameter into the email as follows:

      ${notification.message.webUi.url}?smcid=mentions

      So, having the parameter after the generated URL was stopping the anchor within the generated URL from working.

      I'll give your example a try and will let you know if we have any success.

      thanks again,
      Ben