2

I'm wondering how I can get multiple form field values into Google Site Search. For instance, I have a search form that has a drop down for year, make and model.

Once submitted I would like those three values to be submitted as one string to Google Site Search. My URL after submitting looks like mysite.com/index.php?s=1&year=2007&make=Toyota&model=Tundra

I have already created a query parameter in my Site Search Settings in Google Analytics called search. I just need help programmatically doing the rest.

1
  • I just started looking into having my own search form (style wise) last night and found that it is a lot of reading and testing. I will hit it again soon. I wish I had an answer. But I am glad you asked this question. I am interested in it too. I could benefit from the answer since your model is a good idea for some of what I do. One up-vote. Hopefully someone will have a solid answer for you.
    – closetnoc
    Nov 24, 2014 at 18:37

1 Answer 1

3

You can push data to analytics on search results site loading that way:

analytics.js: ga('send', 'pageview', '/search_results.php?search='+make+' - '+model+' - '+year);

But you need to get GET params from URL. Example:

function get(key_str) {
if(window.location.search) {
    var query = window.location.search.substr(1);
    var pairs = query.split("&");
    for(var i = 0; i < pairs.length; i++) {
        var pair = pairs[i].split("=");
        if(unescape(pair[0]) == key_str)
            return unescape(pair[1]);
    }
}}
2
  • so i'll have my regular ga pageview event, then another one? Nov 25, 2014 at 20:32
  • Yes, it's harming a stats, but the best way in your case Nov 26, 2014 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.