Showing results for 
Show  only  | Search instead for 
Did you mean: 

Neat idea: Add Google Analytics tracking codes to your community emails

I just implemented a pretty nifty little enhancement - I added Google Analytics tracking codes (UTM) to each of the links in the standard Lithium-sent emails. So, now I have some visibility into how much traffic these emails are generating.


It has been just over 24 hours since launch, so I don't have a ton of results, but it's really nice to know this data will be trickling in! 


I thought others may be interested in doing this to get some visibility into email usage. It's easy - just add the appropriate UTM codes to each of the URLs in each end-user-visible message template via Studio. I decided to use source=communitymembers and medium=email for each of them, since I'm already using that scheme in marketing emails. For the campaign, I'm using the name of the template (the name from the URL, such as immediate_general for the "General Subscription Notification")


Example: An updated URL in the "General Subscription Notification" email (available in Studio at: https://[STAGING-URL]/t5/bizapps/bizappspage/tab/community%3Astudio%3Atext-editor%3Aemail?email=immediate_general&lang=en):

<a href="${notification.message.webUi.url}?utm_source=communitymembers&utm_medium=email&utm_campaign=immediate_general">${notification.message.subject}</a> 

Some early results are that the "General Subscription Notification" (immediate_general) is leading the pack in terms of clicks:




17 Replies 17

Don't the URLs in many of the email notifications have anchors (eg. #M3214) when referencing a post? I would assume that putting tracking parameters on the end of this URL would either break the tracking or break the anchor (or both).

@CarolineS you seem to have the tracking coming through, have you done this with any notifications that include a post URL? If so, what was the experience like?

A most excellent question, @DanK. I looked up the code I added to the email templates, and it's along the lines of:


<a href="${notification.messageUrl}?utm_source=communitymembers&utm_medium=email&utm_campaign=subscription_digest">View</a>


This creates links like:

The "?" in this URL then seems to automatically convert into the URL-encoding for the "?", or %3F - see below:

Which means I'm actually not getting tracking for these links that have anchors! Good to know! Not sure if there's a solution to this? Any ideas?


I was playing around yesterday as I am keen on getting tracking into our templates for the exact reasons that you did.

One thing that I did discover is that you can do is change the URL variable ${notification.message.webUi.url} to ${notification.message.discussion.webUi.url} and it will return the URL for the topic rather than the post, which means that it does not take the user directly to the message in question (removing the # anchor parameter). This makes the tracking work but it doesn't take the user to the specific comment that generated the notification.

This is okay in a situation where a solution is involved on my community, as we float those to the top, but I suspect it would be a poor user experience for a reply notification in the instance of a multi-page thread as it wouldn't even take the user to the right page let alone the right comment.

When replying to this specific thread here I noticed that the Khoros Atlas team have actually put the codes on the end of the URL and encountered the same issue;

I am not 100% sure how the email templates work but I suspect to get a good user experience you would need to be able to store variables as strings, cut them up and them put back together with the tracking between the URL and the anchor strings. Perhaps someone with a bit more dev in their title could work something out 😛


@DanKgood find that Khoros themselves have this error too! Agree that it’s not a great solution to just remove the anchor, especially as some discussions get looooooong. 

I do wish Khoros would just provide some amount of email tracking so we didn’t need this hacky solution anyway!


Okay, so it has been ~15 years since I dropped out of my programming course at uni so there may be a more elegant solution than I have found BUT I have found a way to keep the anchor.

I have highlighted in red the parts that you will need to change to suit your requirements but basically the code below takes the URL, checks for a # and if one is found splits it into two text strings (one containing the URL without the anchor and the second containing just that value eg. #M1234 ). Then the URL is reconstructed by inserting your UTM parameters between the two parts and setting it as a variable you can use

#set ( $tempurl = ${notification.message.webUi.url})#if( $tempurl.contains('#'))
#set ($hashindex = $tempurl.indexOf('#'))
#set ($urlstart = $tempurl.substring(0,$hashindex))
#set ($urlend = $tempurl.substring($hashindex))
#set ($tempurl = "${urlstart}?utm_source=community&utm_medium=email${urlend}")
#set ($tempurl = "${tempurl}?utm_source=community&utm_medium=email")

I put this code towards the top of the template and then simply used my new variable $tempurl in place of all references to the message url within the template.

Note that the code must precede any attempts to use the variable or it will break (hence why I put it towards the top).

EDIT: I just realised the original solution did not put tracking on when the URL had no # (although I will be using it where I KNOW a # exists) so I have added an else statement to do that.

Wow, @DanK, awesome! I'll steal this!

Thanks @DanK !


Great thread everyone!  Does this give you more than the 'newish' Analytics section titled Email?  See the screenshot below:



Welcome to the Technology board!

Curious about our platform? Looking to connect on social technology? You've come to the right place!

Are you a Khoros customer? For direct assistance from our Support team, please visit the Support Forum.