Forum Discussion
Can you please let me know where you put the google analytics java-script that is used to set up the google analytics object? Also, what is the error you are getting when the script runs? Is there a javascript error or something else?
Please post the code (excluding any tracking codes of course) and let me know where you place it.
In your previous post, you said that you are seeing some data in your google analytics, is the data coming from the community or from somewhere else?
Thank you,
Yuri
- iftomkins11 years agoMaven
Hi Yuri,
Sure thing! Here are the scripts that include GA events. The first 2 work, and the last one which is trying to attach a listener to the auto-suggest results (see screenshot attached) does not work.
As AndrewF mentioned in this previous post, it's likely because the GA event is not bubbling up because of the Lithium script acting on those same auto-suggest results.
- These scripts are in the Hitbox area of the Desktop Skin
- No javascript errors are occurring, it's just that the script is not running. When a console.log is placed on the 3rd script, its output never appears in the browser console.
1.
//Tracks first focus event via Google Analytics. WORKS, currently collecting data.
$("#custom-search-border .lia-search-input-message").one("focus",function(){
var category = $(".custom-search-wrapper .search-granularity option:selected").val().split('|')[0];
_gaq.push(['_trackEvent', 'SearchAskComponent', category, 'focus']);
console.log('SearchAskComponent: Focus:',category);
});2.
//change search functionality to Ask a Question post functionality, and track clicks. WORKS, currently collecting data.
$("#lia-body .lia-content .custom-search-wrapper .lia-button-Continue-action").click(function() {
var subject = $(".custom-search-wrapper .SearchForm .lia-search-input-message").val();
var category = $(".custom-search-wrapper .search-granularity option:selected").val().split('|')[0];
var url = getPostUrl(category, htmlEncode(subject));
if (subject != "${text.format('form.AskAnExpert.default_text.title')}") {
_gaq.push(['_trackEvent', 'SearchAskComponent', category, 'postByClick']);
window.location.href = url;
} else {
}
});3.
//Trying to track click-throughs of auto-suggest results via GA. Attaching listener to link wasn't working, so this one tries to listen for clicks on the autocomplete container, but this didn't work either. Not working, no data is being collected. Likely because a Lithium script is redirecting you to a new page before this event trigger is able to fire.
//$("#lia-body .lia-content .custom-search-wrapper .SearchForm.lia-form-inline .lia-autocomplete-container").on("click",function(){
var category = $(".custom-search-wrapper .search-granularity option:selected").val().split('|')[0];
_gaq.push(['_trackEvent', 'SearchAskComponent', category, 'clickThrough']);
});- YuriK11 years agoKhoros Expert
Hey iftomkins,
Sorry for not responding to you sooner.
The problem here is that the results don't exist until you start typing items in. So when your javascript is running (on page load) it can't set up the on click on something that doesn't exist.
You may be able to listen to the onkeypress event of the search text field, and then loop through all the result links and attach to their onclick events. I'm not sure if this would work, or if it would cause any performance degradation, but it's worth a try.
Hope this helps,
Yuri
Related Content
- 7 months ago
- 6 months ago
- 4 months ago