Here is a solution for Marketo Real-Time Personalization (RTP) users to see clicks from the Content Recommendation Engine within Google Analytics. Once a visitor clicks the Content Recommendation bar, an event is sent to Google Analytics under Event Category “RTP-Recommendations”. In Analytics, the Recommendation Text (as it appears in the bar) will be appended to Event Label and the URL of the recommended asset will be appended to Event Action.
The script works for both Classic Google Analytics and Google Universal Analytics. This tag should be pasted at the end of the HTML page code, so it will be the last tag before the </body> tag.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
$( document ).ready(function() { if(document.getElementsByClassName("insightera-bar-content").length >0){ document.getElementsByClassName("insightera-bar-content")[0].getElementsByTagName('a')[0].addEventListener("click", function(){ assetName = document.getElementsByClassName("insightera-bar-content")[0].getElementsByTagName('a')[0].innerText; assetURL = document.getElementsByClassName("insightera-bar-content")[0].getElementsByTagName('a')[0].href; assetURL= assetURL.substring(assetURL.lastIndexOf("/"),assetURL.indexOf("?iesrc")); console.log(assetName + " | " + assetURL); if(typeof(_gaq) != "undefined"){ //Classic _trackEvent("RTP-Recommendations", assetName , assetURL , {'nonInteraction': 1}); }else if(typeof(ga) !="undefined"){ //Universal ga('send', 'event',"RTP-Recommendations", assetName , assetURL, {'nonInteraction': 1}); } }); } }); |
As shown in the image below, asset names will show up under the events report in Google Analytics.