Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to achieve "Tracking No Result Search Keywords" using Custom Parameter #9421

Closed
sumit140 opened this issue Dec 21, 2015 · 4 comments
Closed
Assignees
Labels
answered For when a question was asked and we referred to forum or answered it.
Milestone

Comments

@sumit140
Copy link

Hey Team, I am trying to achieve "Tracking No Result Search Keywords" using custom parameter instead of using default search parameter. But facing some issues in getting proper result. Also below I am maintaining my code what I have tried so far:

function searchCheck() {
 if (document.getElementsByName('_3_keywords') && document.getElementsByName('_3_keywords')[0]) {
  var keywords = document.getElementsByName('_3_keywords')[0].value;
  if (document.getElementsByClassName('portlet-msg-info')
    && document.getElementsByClassName('portlet-msg-info')[0]) {
   var searchResults = document.getElementsByClassName("portlet-msg-info")[0].value = "No results were found that matched the keywords:";
   if (searchResults == "No results were found that matched the keywords:") {
    if (document.getElementsByName('_3_keywords') && document.getElementsByName('_3_keywords')[0]) {
     var searchCount = 0;
     //code to track search with no result
     console.log("keywords:::::::::" + keywords + "count" + searchCount);
    _paq.push([ 'trackSiteSearch', keywords + '', false, 0 ]);

    }
   }
  } else {
   //code to track search keyword having results
   var searchCount = 15;
   console.log("Sucess: keywords:::::::::" + keywords + "count" + searchCount);
    }
 }
}

Here '_3_keywords' is my custom parameter. Also, I have tried this as well: "_paq. push (['setCustomUrl', keywords + '&search_count=' + searchCount]);" But unable to get the no search keyword result. Can you please help me where I am doing wrong so that I can resolve my issue asap.

@tsteur
Copy link
Member

tsteur commented Dec 21, 2015

Can you try _paq.push([ 'trackSiteSearch', keywords + '', 0 ]);. Not sure why you set it as custom data? Also setCustomUrl should work as explained here: http://piwik.org/docs/site-search/#tracking-no-result-search-keywords

_paq.push(['setCustomUrl', document.URL + '&search_count=' + searchCount]);
_paq.push(['trackPageView']);

You need to track a pageview after setting the custom URL

@tsteur
Copy link
Member

tsteur commented Dec 21, 2015

Please reopen if you still experience the issue

@tsteur tsteur closed this as completed Dec 21, 2015
@tsteur tsteur added the answered For when a question was asked and we referred to forum or answered it. label Dec 21, 2015
@tsteur tsteur added this to the 2.15.1 milestone Dec 21, 2015
@sumit140
Copy link
Author

Hi Thomas,

I have solved my issues by calling trackpageview function based on
condition...it's work fine for me.
Thanks a lot for your all support.
On 22-Dec-2015 2:03 am, "Thomas Steur" notifications@github.com wrote:

Can you try _paq.push([ 'trackSiteSearch', keywords + '', 0 ]);. Not sure
why you set it as custom data? Also setCustomUrl should work as explained
here:
http://piwik.org/docs/site-search/#tracking-no-result-search-keywords

_paq.push(['setCustomUrl', document.URL + '&search_count=' + searchCount]);_paq.push(['trackPageView']);

You need to track a pageview after setting the custom URL


Reply to this email directly or view it on GitHub
#9421 (comment).

@tsteur
Copy link
Member

tsteur commented Dec 23, 2015

Glad to hear and thx for letting us know

@tsteur tsteur self-assigned this Dec 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it.
Projects
None yet
Development

No branches or pull requests

2 participants