inserting google advertisements with html - css

Good day,
I'm sorry if this might be a duplicate question but most of the questions speak of Google AdSense and I've never used that.
Getting to the point, I would like to know if anyone knows how to add an advertisement from Google to an HTML 5 site.
I am doing a project. The actual site files will be on the local drive, but I would like to i.e. insert an on my page that would draw some random Google Ads and place them in this section.
I do not wish to create an advert or anything of the sort. Let's say that I have the section at a 600px by 100px block, I would like to have that "draw" any ads of a certain category to be placed there at run time.
Like I said the page itself will be local, but using internet access the page should fetch these ads.
Thank you in advance for a speedy reply, and I would like to apologize if I over explained.

It is very easy to insert the Google Adsense in HTML just paste your code inside the body tag and use bootstrap or CSS3 for the positioning.
<html>
<head>
This is the head of your page
<title>Example HTML page</title>
</head>
<body>
**Paste your google adsense code inside the body**
This is the body of your page.
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Homepage Leaderboard -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1234567890123456"
data-ad-slot="1234567890"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</body>
</html>

Refer Get and copy the ad code (click "If you haven't yet created an ad unit under "How to get and copy your ad code")
Then refer Where to paste the ad code in your HTML
It's explained pretty well

<html>
<head>
This is the head of your page
<title>Example HTML page</title>
</head>
<body>
This is the body of your page.
<!-- Ad block -->
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1234567890123456"
data-ad-slot="1234567890"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<!-- End of Ad block -->
</body>
</html>

Adsense can not be loaded from localhost or from a saved html file. It will not work.
Google checks if the domain is accepted into adsense before showing an ad.
So when you load an ad from local, domain property will be missing.

Related

How did Google Ads find out my campaign's conversion even if customer visited different HTML page before firing final tracking code?

I have set up a Google Ads campaign.
If users search "Cool Clothes" in Google, my campaign website will show in search results.
Now, the user will follow these steps:
Click the campaign website link in the Google search result
Go to https://cool-clothes.com/my-campaign
The user wants to signup an account, so users click the "Sign Up" button
I use Facebook for login, so users will redirect to https://facebook.com first, asking for some permissions.
After permission granted, Facebook will redirect back to my website called https://cool-clothes.com/new-user
https://cool-clothes.com/new-user is where I put the Google Ads tracking code
https://cool-clothes.com/new-user HTML looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cool Clothes</title>
<!-- Global site tag (gtag.js) -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=AW-XXX"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "AW-XXX");
</script>
<!-- Event snippet for conversion page -->
<script>
gtag("event", "conversion", {
send_to: "AW-XXX/XXX",
});
</script>
</head>
<body>
Thanks for Sign Up!
</body>
</html>
Here comes my question, the user goes through multiple different HTML pages, how did Google Ads know how to count the conversion?
Are Google Ads using first-party cookies to do this?
Well, yes.
GA uses a user identifier cookie that identifies the user. And more on top of that. And it's able to "backfill" user's actions preceding the conversion as such that led to conversion. And a lot more on top of that.
It's also not a secret, Google has documentation on it: https://support.google.com/google-ads/answer/2407785?hl=en

Google tags, Code apears in my site

I put google tags on my website and when I open the page it shows the code, how to solve it?
<head><script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');
</script>
and
<body>
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX" height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
</body>
It would appear that you have a custom HTML tag with a Facebook tag and forgot to wrap this in <script></script> tags (also your example code is missing the script tags around the GTM script. Also don't be confused by the fact that the word "tag" has three different meanings in this sentence).
Add script HTML tags (<script></script> ) to you FB tag and publish, then the problem should be solved.
The problem is not your "Google Tags", it's a custom tag you've used (facebook as i look in your code) You must have forgot around a custom tag. Dig in your tag section of GTM.

How to add Google analytics code to php pages, per Google's instruction?

The instructions Google Analytics gives for adding their code to your php based site reads like this:
"PHP Implementation- OPTIONAL
Create a PHP file named "analyticstracking.php" with the code above and include it on each PHP template page. Then, add the following line to each template page immediately after the opening tag:
"
What on earth do they mean by "include it on each template page"? How do you include a file on your template page?
I'm thinking that the instructions after the word "Then," are how you add it to your template page. Is that correct? Does Google really have such bad writers that they would write a confusing redundancy like that? What am I missing?
Make sure that your pages have ".php" extension and that your server is running php.
Then, on each page type the following
php code:
<?php include("analyticstracking.php"); ?>
Or if your analytics file is placed in different directory than your pages:
<?php include("some_directory/analyticstracking.php"); ?>
As opening tag they mean the <html> tag at the top of the code.
Here is an example:
HTML/PHP PAGE CODE:
<html>
<?php include("some_directory/analyticstracking.php"); ?>
<head>
<!-- your head content goes here -->
</head>
<body>
<!-- your body content goes here -->
</body>
</html>
Hope that helps you...

Country-specific URLs pointing to the same content, is it possible?

I need my website to have different URLs depending on the country you're accessing it from; it would work like this:
www.mypage.com ==> for users accessing from Spain - content in Spanish.
www.mypage.com/en-uk/ ==> for users accessing from UK - content in English.
www.mypage.com/en-br/ ==> for users accessing from Brazil - content in English.
www.mypage.com/en-il/ ==> for users accessing from Israel - content in English.
As of now there are only two versions of the web (Spanish and English), so for all specified countries (except Spain) the different URLs should point to exactly the same content. I'm trying to find a solution that doesn't involve having the same content copied 3 times.
I'm trying to to this with the following plugins:
WPML
Geo Redirect
But I'm struggling to make it work. I understand the problem may seem a little vague, it's just that I'm pretty lost and I'm not sure how to approach this. All suggestions would be appreciated.
Try using a redirected URL. You can create the other (non-content) pages (www.mypage.com/en-il/) and add to the header a redirect:
<html>
<head>
....
<script>
// this will load the corresponding page
window.location.assign("http://www.mypage.com/en-uk/");
</script>
</head>
<body>
<!-- empty -->
</body>
</html>
Here is a second example where you can do the redirect from a single 404 page. Just place this code at the top level (home) of the web site in a page named 404.shtml
<html>
<head>
<script>
window.onload = function()
{
// Get the referring URL
var ref = '<!--#echo var="REDIRECT_URL"-->';
// Break into components
//
comp = ref.split('/');
if ( comp.length > 1 )
{
switch ( comp[ 1 ] )
{
case "en-br":
case "en-il": // this will load the corresponding page
window.location.assign("http://www.mypage.com/en-uk/");
break;
}
}
</script>
</head>
<body>
<!-- 404 page handling here -->
</body>
</html>

Adding DFP Script to Wordpress

I am playing with Wordpress 3 for the first time and had a quick question.
I am placing ads on a site and wondered the best practice to add in the script. The code that Google generates is in 2 parts, one for the of the page and one where the ad should go
The head code is in the form
<script type='text/javascript' src='http://partner.googleadservices.com/gampad/google_service.js'>
</script>
<script type='text/javascript'>
GS_googleAddAdSenseService("ca-pub-123123");
GS_googleEnableAllServices();
</script>
<script type='text/javascript'>
GA_googleAddSlot("ca-pub-123123", "300x250_Ad");
</script>
<script type='text/javascript'>
GA_googleFetchAds();
</script>
Then the code for the ad is:
<!-- ca-pub-123123/300x250_Ad -->
<script type='text/javascript'>
GA_googleFillSlot("300x250_A");
</script>
I downloaded a plugin Advertising Manager that allows me to add ads into the page but only seems to allow putting in one block of code. I can add all the code joined up but if I want to add other ad positions later it is not the best...
I can't go into my Theme and add the code in there, as I am using Multiple Sites the code will need to difer from site to site, is there something very simple I am missing to add stuff into the and then I can use Advertising Manager to display the individual ad code...
Try using the the AdSense-Deluxe WordPress Plugin
It would appear the plugin has a bug, the shortcode you're using is calling a function which is directly outputting the code for DFP (which is called when wordpress is preparing the page content, hence it appearing all at once at the top) instead of returning it to be inserted throughout the content.

Resources