Google Analytics and Google Adsense support

We have finished development for this blog the only thing remaining is google analytics and google Adsense.

for google analytics, we are using frontity google analytics package but somehow it does not work. can you please help us with that?

and for google Adsense we are using third party AdSense providers they give us small javascript to add in the head tag and another script tag which defines ad places, and then call their SPA hook with every route change So what is the best way to add script tag in the head we need to call after dom content loaded.

**Head script**

<script data-cfasync="false" type="text/javascript">
(function(w, d) {
var s = d.createElement('script');
s.src = '//[cdn.adpushup.com/38602/adpushup.js](http://cdn.adpushup.com/38602/adpushup.js)';
s.type = 'text/javascript'; s.async = true;
(d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
})(window, document);
</script>


add tag

336x280
<div id="2dd25ff6-e526-45f9-9b20-4cb6277fdbb2" class="_ap_apex_ad">
	<script>
		var adpushup = adpushup || {};
		adpushup.que = adpushup.que || [];
		adpushup.que.push(function() {
			adpushup.triggerAd("2dd25ff6-e526-45f9-9b20-4cb6277fdbb2");
		});
	</script>
</div>

SPA hook

!function(){
    window.adpushup.init();
}()

So we already added script tag in head and SPA hook but How can I insert add tag?

Could you please provide more details about the problem?

I would add the <script> using <Head>, the <div> using a React Component with useEffect for the push. Something like:

const AdSense = ({ id }) => {
  React.useEffect(() => {
    const adpushup = window.adpushup || {};
    adpushup.que = adpushup.que || [];
    adpushup.que.push(() => {
      adpushup.triggerAd(id);
    });
  });
  return <div id={id} class="_ap_apex_ad" />;
};

Finally, I would do the init on the afterCSR (after client-side rendering) action:

export default {
  state: {
    //...
  },
  actions: {
    afterCSR: () => {
      window.adpushup.init();
    },
  },
};

if you want to do this, how you solved the add file ads.txt?
Are you use vercel?

I’ll answer you in the other thread you created: How do i add ads.txt to my frontity project?

Sure!