Analytics
5.3K members online now
5.3K 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 Search Console without URL

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I am using wordpress and multisite with Theme Avada. In it's searchform.php I have set up this code below, which are identifying on what site you are on and in what language the GSC-script are to run.

 

<?php
$blog_id = get_current_blog_id();
?>


<?php if($blog_id == 10): ?>

    <form role="search"  method="get" action="<?php echo home_url( '/' ); ?>">
<script>
  (function() {
    var cx = '003272623460350056943:flrk_u5i0jo';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src=(document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search>
</form>

<?php elseif($blog_id == 11): ?>

<form role="search"  method="get" action="<?php echo home_url( '/' ); ?>">

    <script>
  (function() {
    var cx = '003272623460350056943:uyjgjo6fjto';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src=(document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search>
</form>

<?php elseif($blog_id == 12): ?>

<form role="search"  method="get" action="<?php echo home_url( '/' ); ?>">

<script>
  (function() {
    var cx = '003272623460350056943:guia7ja3mmm';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src=(document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search>
</form>

<?php elseif($blog_id == 13): ?>

<form role="search"  method="get" action="<?php echo home_url( '/' ); ?>">

<script>
  (function() {
    var cx = '003272623460350056943:kyr1vwrcjqa';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src=(document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);

  })();
</script>
<gcse:search></gcse:search>
</form>

<?php elseif($blog_id == 14): ?>

<form role="search" method="get" action="<?php echo home_url( '/' ); ?>">

<script>
  (function() {
    var cx = '003272623460350056943:xq2krver5ds';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src=(document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search>
</form>

<?php elseif($blog_id == 15): ?>

<form role="search" class="searchform" method="get" action="<?php echo home_url( '/' ); ?>">
	<div class="search-table">
		<div class="search-field">
			<input type="text" value="" name="s" class="s" placeholder="<?php echo __( 'Search ...', 'Avada' ); ?>" />
		</div>
		<div class="search-button">
			<input type="submit" class="searchsubmit" value="&#xf002;" />
		</div>
	</div>
</form>

<?php endif; ?>

My problem is that I can't get it right to collect the data into GA due to I'm in this stage don't have an URL to find the search-string. Does anyone know how I can change the GSC-script so I got a URL for the search? The blogid 15 standard for Avada and no need for GSC, and there it works with URL fine. Any ideas?

1 Expert replyverified_user

Re: Google Search Console without URL

Top Contributor
# 2
Top Contributor
Hi Robin
Unfortunately not. You need an actual URL. You could try setting virtual pageviews on search, but that's up to you to code into your theme.