Chuks33's avatar

Adsense code on blade template

Is there a particular way Adsense code is supposed to be added to blade.php files?

I have added the below code in a div on my template file yet nothing appears. It's been roughly 2 weeks now.

(adsbygoogle = window.adsbygoogle || []).push({});
0 likes
15 replies
ftiersch's avatar

Blade just renders to normal HTML...

  1. Have you added script tags around it?
  2. Have you included the rest of the ads library?
Chuks33's avatar

@FTIERSCH - 1. Yes

(adsbygoogle = window.adsbygoogle || []).push({});
  1. Which library? I thought the ad code was sufficient...
Chuks33's avatar

@MVD - I added the script tags.

I didn't test within test mode. I'll give it a shot. Thanks

Chuks33's avatar

@mvd I just created a new ad unit. I added data-ad-test="on" as a parameter to the ad code yet the ad is still not appearing.

mvd's avatar

@chuks33 can you give us the full blade template code wherein you add the Adsense code?

Chuks33's avatar

@mvd

@extends('layouts.master')

@section('title')
    {{$post->username}} on ClassDey: {{$post->post_title}}
@endsection
@section('og-title'){!! $post->post_title !!} @stop
@section('og-url'){!! url()->current() !!} @stop
@section('meta-description'){!! $post->post_body !!}  @stop

@section('content')
    @include('includes.message-block')
    <!-- Section: Follow -->
      <section class="section section-follow center">
        <div class="container">
          <div class="row">
            <div class="col s12">
              <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
                <!-- CD-01 -->
                <ins class="adsbygoogle"
                     style="display:block"
                     data-ad-test="on"
                     data-ad-client="ca-pub-xxxxxxx"
                     data-ad-slot="xxxxxxxxx"
                     data-ad-format="auto"
                     data-full-width-responsive="true"></ins>
                <script>
                (adsbygoogle = window.adsbygoogle || []).push({});
              </script>
            </div>
          </div>
        </div>
      </section>
      <section class="section section-follow teal darken-1 white-text center">
        <div class="container">
          <div class="row">
            <div class="col s12">
              <a style='border-radius: 4px !important;font-size: 14px;background: #fff !important; padding: .1em .5em;color: rgb(0,139,139)' href="{{url('/fposts')."/".$post->category_id}}/filter">
                <span>{{$post->name}}</span>
              </a>
              <h5>{{$post->post_title}}</h5>
            </div>
          </div>
        </div>
      </section>
      <section class="section section-main"><!-- Bread crum -->
        <div class="container">
          <div class="row row-1">
            <a style='border-radius: 4px !important;font-size: 14px;background: #fff !important; padding: .1em .5em;color: rgb(0,139,139)' href="{{url('/fposts')."/".$post->category_id}}/filter">
              <span>< {{$post->name}}</span>
            </a>
          </div>          
        </div>
      </section>
      <section class="section section-main">
        <div class="container">
          <div class="row row-1">
            <div class="col">
              <div>
                <a href="/profile/{{$post->username}}"><img src={{$post->avatar}} alt="{{$post->username}}" style='width: 50px; height: 50px;border-radius: 50%'></a>
              </div>
            </div>
            <div class="col">
              <div>
                <span class="title"><a href="/profile/{{$post->username}}">{{$post->username}}</a></span> {{$post->created_at->diffForHumans()}}
              </div>
              <div>
                <p>
                  @if(!empty($post->image_url))
            <img style="width:50%" alt="{{$post->post_title}}" src="{{$post->image_url}}">
        @endif
        <br />
      {!! nl2br(e($post->post_body))!!}</p>

              </div>
            </div>
          </div>          
        </div>
      </section>
 <section class="section section-main"><!-- Share button -->
    <div class="container">
      <div class="row row-1">
        <a href="whatsapp://send?text=From IUO's virtual bulletin board {{ url()->current() }}" class="btn btn-large white green-text"><i class="small fa fa-whatsapp"></i> Share</a>
      </div>          
    </div>
  </section>
      <!-- Section: Comment -->
  <section class="section section-contact scrollspy">
    <div class="container">
      <div class="row">        
          <div>
            <h5>Comment</h5>                      
            
            {!! Form::open(['action' => 'PostsController@storeComment', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}

            {{Form::hidden('parent_id', $post->id)}}

            <div class="input-field">
              {{Form::textarea('comment', '', ['id' => 'article-ckeditor', 'class' => 'materialize-textarea', 'placeholder' => 'Write a comment...'])}}
            </div>
            

            {{Form::submit('Submit', ['class'=>'btn btn-primary'])}}
              
            {!! Form::close() !!}          
        </div>        
      </div>
    </div>
  </section>
  <!-- Section: Comment list -->
  <section class="section">
    <div class="container">
      <div class="row">
        <div class="col s12">
          <ul id="productData" class="collection">
          @if(count($comments) > 0)
              @foreach($comments as $comment)
                  
                <li class="collection-item avatar">
                    
                    <a href="/profile/{{$comment->username}}"><img src={{$comment->avatar}} alt="{{$comment->username}}" class="circle"></a>
                  <span class="title"><a href="/profile/{{$comment->username}}">{{$comment->username}}</a></span> {{$comment->created_at->diffForHumans()}}
                  <p>{{$comment->post_body}}<br>
                     
                  </p>
                  
                </li>
             
              @endforeach
              @else
                  <li class="collection-item">No comments found</li>
              @endif
           </ul>
        </div>
      </div>
    </div>
  </section>
    <article class="post" data-postid="{{ $post->id }}">
        <!-- <div style='background-color:rgb(0,139,139);text-align: center;'>
            
            <ul>  
                <li>
                    <a style='border-radius: 4px !important;font-size: 14px;background: #fff !important; padding: .1em .5em;' href="#">
                    <span>For Sale</span>
                    </a>
                  
                </li>              
                <li>
                    <h2 style='margin: 0; font-size: 16px; font-weight: normal; line-height: 1.5em; color: #fff'>
                        {{$post->post_title}}
                    </h2>
                  
                </li>
             </ul>

        </div> -->
      
       
     
        <!-- <a href="{{ route('report1', ['id' => $post->id]) }}">Report</a>
 -->        <!-- {!!Form::open(['action' => ['PostsController@report', $post->id], 'method' => 'POST', 'class' => 'pull-right'])!!}
            {{Form::submit('Report', ['class' => 'btn btn-danger'])}}
            {{Form::hidden('id', $post->id)}}
        {!!Form::close()!!} -->

    
    </article>

    <!-- <ul id="productData" class="collection">
    @if(count($comments) > 0)
        @foreach($comments as $comment)
            
                <li class="collection-item avatar">
                    
                    <a href="/profile/{{$comment->username}}"><img src={{$comment->avatar}} alt="{{$comment->username}}" class="circle"></a>
                  <span class="title"><a href="/profile/{{$comment->username}}">{{$comment->username}}</a></span> {{$comment->created_at->diffForHumans()}}
                  <p>{{$comment->post_body}}<br>
                     
                  </p>
                  
                </li>
           
        @endforeach
    @else
        <li class="collection-item">No comments found</li>
    @endif
     </ul> -->
    
    <script>
        var token = '{{ Session::token() }}';
        var urlLike = '{{ route('like') }}';
    </script>
    
@endsection
Snapey's avatar

in your browser dev tools

a) check for any errors in the network tab when you load the page

b) check for any console errors

Chuks33's avatar

@SNAPEY - a) THe network tab didn't show any errors

b) The console showed this error:

The resource https://pagead2.googlesyndication.com/pagead/js/r20190530/r20190131/show_ads_impl.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.

Chuks33's avatar

@MVD - It's a public page.

I'm getting in the console:

Failed to load resource: the server responded with a status of 403 ()

Perhaps

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

should be placed in between the header tags leaving only

<ins class="adsbygoogle"
                     style="display:block"
                     data-ad-test="on"
                     data-ad-client="ca-pub-xxxxxxx"
                     data-ad-slot="xxxxxxxxx"
                     data-ad-format="auto"
                     data-full-width-responsive="true"></ins>
                <script>
                (adsbygoogle = window.adsbygoogle || []).push({});
              </script>

in the body of the blade template...

Chuks33's avatar

@MVD - Much thanks! After approval from Google ads are showing up on the blade templates.

Thank you @ftiersch and @snapey for your contributions.

Snapey's avatar

Glad its sorted

You need to spend a little time understanding the network tab in the browser

I asked

a) check for any errors in the network tab when you load the page

and you said

a) THe network tab didn't show any errors

but then in the following replies

I'm getting in the console:

Failed to load resource: the server responded with a status of 403 ()

That 403 should be present in the network log also.

Please or to participate in this conversation.