Analytics
6.5K members online now
6.5K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Google Analytics conflict with Search Engine code

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi,

 

We are using Google Analytics (GA) on  our library website. We have a search engine on the main page of our website that searches holding in our local and partner library catalogs. This search engine has a drop down menu of indexes (keyword, title, author, subject, ISBN, and Journal Title), with Keyword being the default index. Each of the indexes has a prefix that displays in the search box before the query once the query is submitted (for instance, if title was selected when the user is submitting their query, this would be displayed "ti: query" in search box with accompanying results). When we include the GA code, the prefix is doubled for all indexes except keyword (so for title it would be "ti:ti: query"). When we remove the GA code, the prefix appears normally, and is not doubled. The functionality of the search box works with the GA code, the only issue is the double prefix. A  relatively minor issue, but still one we'd like to resolve.  

 

We've done quite a bit of research on this, but have yet to find a solution. I've included the code below if anyone would like to view it. Any insight would be so greatly appreciated!

 

GA code

<script>

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXXXXX-X', 'auto');
ga('send', 'pageview');

</script>

 

SEARCH BOX CODE (I've removed references to our library in the code and replaced with XX)

<!--Quick Search-->
<div id="quicksearch" style="height:80px;">
<form method="get" id="worldCat" action="http://XX.on.worldcat.org/search" onsubmit="worldCatSubmit()">
<table cellpadding="0px" cellspacing="0px 3px">
<tr>
<td style="border-style:solid;border-color:#cccccc;border-width:1px;">
<!--Search Box Dimensions-->
<input type="text" id="queryString" name="queryString" placeholder="Find books, articles, and more" value="Find books, articles, and more" title="WorldCat Search" />
<input type="hidden" name="scope" id="scope" value="" />
</td>
<td style="border-style:none;" width="42px">
<!--The search button-->
<input type="image" value="Go" src="/files/images/Search.png" alt="Search" onclick="var _this=this;ga('send', 'event', 'WorldCat Beta Search Box', 'WorldCat Discovery Search', jQuery(_this).parents('form').first().find('input:text').val(), {'hitCallback':function(){jQuery(_this).parents('form').first().submit();}});" />
</td>
</tr>
</table>
<table>
<tr>
<td align="left">
<select name="idx" id="idx" title="Filter">
<option value="kw:">Keyword</option>
<option value="ti:">Title</option>
<option value="au:">Author</option>
<option value="su:">Subject</option>
<option value="sn:">ISBN/ISSN</option>
<option value="so:">Journal Title</option>
</select>
</td>
<td align="right"><strong><a href="https://XX/Search/Home">I-Share</a></strong> |
<strong><a href="http://XX.on.worldcat.org/advancedsearch" target="_blank" id="worldCatAdv">Advanced Search</a></strong>
</td>
</tr>
</table>
</form>
<input type="radio" id="searchBeta" name="searchType" value="beta" checked="checked" style="margin-top:-1px; vertical-align:middle;" />
<label for="searchBeta">Beta Search</label>
<input type="radio" id="searchCurrent" name="searchType" value="current" style="margin-top:-1px; vertical-align:middle;" />
<label for="searchCurrent">Current Search</label>
</div>

 

JAVASCRIPT FOR SEARCH ENIGNE

jQuery().ready(function($){
$('.tabs').tabs();
$('.tabs ul li a').click(function(e){e.preventDefault();});
if ( /Android|webOS|iPhone|iPod|Blackberry|Windows Phone|Opera Mini/i.test(navigator.userAgent)){
$('#indexButtons img').attr('src', function(i, e){
return e.replace(/\.png/g, "Mobile.png");
});
}

$('#searchBeta').change(function(){
$('#worldCat').attr('action', 'http://XX.on.worldcat.org/search');
$('#worldCat #queryString').attr('name', 'queryString');
$('#worldCat #worldCatAdv').attr('href', 'http://XX.on.worldcat.org/advancedsearch');
$('#worldCat input:image').attr('onclick', "var _this=this;ga('send', 'event', 'WorldCat Beta Search Box', 'WorldCat Discovery Search', $(_this).parents('form').first().find('input:text').val(), {'hitCallback':function(){$(_this).parents('form').first().submit();}});");
$('#worldCat #scope').attr('value', '');

});
$('#searchCurrent').change(function(){
$('#worldCat').attr('action', 'http://XX.worldcat.org/search');
$('#worldCat #queryString').attr('name', 'q');
$('#worldCat #worldCatAdv').attr('href', 'http://XX.worldcat.org/advancedsearch');
$('#worldCat input:image').attr('onclick', "var _this=this;ga('send', 'event', 'WorldCat Search Box', 'WorldCat Search', $(_this).parents('form').first().find('input:text').val(), {'hitCallback':function(){$(_this).parents('form').first().submit();}});");
$('#worldCat #scope').attr('value', '0');
});
});

function worldCatSubmit(){
if(jQuery('#worldCat').find(':text').val()!=jQuery('#worldCat').find(':text')[0].defaultValue&&jQuery('#worldCat').find(':text').val()!=''&&jQuery('#idx').val()!='kw:'){
jQuery('#worldCat').find(':text').val(jQuery('#idx').val()+''+jQuery('#worldCat').find(':text').val());
}
};

 

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Norris B
December 2015

Re: Google Analytics conflict with Search Engine code

Top Contributor
# 2
Top Contributor
Hi Norris,

maybe the 'q' parameter is involved in the issue here because it's used in both scripts. You either get some JavaScript wizard to change the coding appropriately. Or you could change to Google Tag Manager on this occation (see for example [1]) to get the Analytics scripting out of sight of your onsite script.

Christoph

[1] http://www.business2community.com/online-marketing/an-ultimate-guide-to-google-tag-manager-01371843

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Norris B
December 2015

Re: Google Analytics conflict with Search Engine code

Top Contributor
# 2
Top Contributor
Hi Norris,

maybe the 'q' parameter is involved in the issue here because it's used in both scripts. You either get some JavaScript wizard to change the coding appropriately. Or you could change to Google Tag Manager on this occation (see for example [1]) to get the Analytics scripting out of sight of your onsite script.

Christoph

[1] http://www.business2community.com/online-marketing/an-ultimate-guide-to-google-tag-manager-01371843

Re: Google Analytics conflict with Search Engine code

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Hi Christoph,

This seems to have worked! Thank you so much for taking the time to respond.

Best,
Brian

Re: Google Analytics conflict with Search Engine code

Top Contributor
# 4
Top Contributor
Glad to hear!