Google Ads Direct Keyword Insertion – Replace Title & H1 with Keyword (JS)

This Snippet will replace your page title and your first occurence of the H1 with the value you provide as url parameter. In this case, just use the parameter „keyword“ and the snippet will replace the page title and your first H1 with its value.

In Google Ads you can specify the parameter of each Ad within your tracking template or just add the parameter manually to your url.

Example:
https://eboosting.net/google-ads-editor-reporting-tool/?keyword=Hey%20there%20-%20Whazzup

<script>
//Save parameter value in variable
var keyword = ""
var url_string = window.location.href; 
var url = new URL(url_string);
var keyword = url.searchParams.get("keyword");
//console.log(keyword);
 
 
//Replace title
if(keyword !== null && keyword !== '') {
   document.title = keyword;
}else{
console.log("noParamNoTitle");
}
 
//Replace the first H1
if(keyword !== null && keyword !== '') {
document.getElementsByTagName("h1")[0].innerText = keyword;
}else{
console.log("noParamNoHeading");
}
</script>

WHERE TO PLACE THIS CODE?

You can place it either directly within your page or you use the Google Tag Manager (which is my preferred way to inject stuff).

Pleasure?

Please share your thumbsup, suggestions, edits, and questions within my comment section down there. 

I love posting snippets for you, but with a bit of feedback, it gets even more fun. 😀

Sharing is caring:

Share on xing
Share on linkedin
Share on whatsapp
Share on facebook
Share on twitter
Share on email

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert