Forum

Thread tagged as: Question, Third-party

How to Add Google Adwords code

Hi

I have been asked to add cost per click code to our Perch pages. I ran a search and can only find a result for how to add Google Analytics.

Please could someone let me know if I need to add code or use a app?

Any help is hugely appreciated

Deb Harrison

Deb Harrison 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can use a regular textarea field, just add the attribute html="true" to stop the code being escaped.

Hi Drew

I am a complete newbie to perch. Where would I add this?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you built a template?

No I haven't.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Deb,

I have been asked to add cost per click code to our Perch pages.

It sounds like you already have a website set up (perhaps built by someone else given you haven't built a template yourself?).

I am a complete newbie to perch. Where would I add this?

The Getting Started series is a good place to start if you're totally new to Perch.

This is a textarea field with html="ture" like Drew suggested:

<perch:content id="adwords" type="textarea" label="Google Adwords" html="true" />

Hi Hussein

Yes this is an existing website that has already been set up and has Perch in place.

This clear needs to be added to the template itself. From teh getting started videos its clear that Perch only edits the actual page content.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

What you edit doesn't have to be page content. The following is the default Google Analytics template that comes with Perch:

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', '<perch:content id="uacode" type="text" label="Web property ID" help="UA-XXXXX-X" />']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'https://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

In the control panel you enter the Web Property ID which is required for the script to work. Just using this as an example to show that you can edit things that aren't "page content".

If you are not familiar with working with templates, it might be a good idea to contact the developer who built the site.

Ok sorry my point was, that you have to add perch tags to the file in order to be able to edit any content from the control panel. Is that correct?

I need to add a Google Analytics code and surround the phone number with a script. I went through the get started videos as suggested and these clearly involve adding the perch tags to the template.

And this is the problem: I cannot get hold of the original developer to obtain this info. They're not even sure who their is website hosted with.

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's probably the place to start - get access to the hosting and then you'll be able to grab a copy of the site to your development environment and make whatever changes necessary.

Hi Deb

Then unfortunately I don't think there's much you can do until you resolve your hosting issue. Once you have ftp access to the source files, then the above solution will sort you out.

Best of luck

Jon

Ok I have the info now. The Google Analytics code I have added with no issues, but the script for the phone numbers is impossible.

<script type="text/javascript">
(function(a,e,c,f,g,h,b,d){var k={ak:"Anumber",cl:"Acode",autoreplace:"1234 567 8901"};a[c]=a[c]||function(){(a[c].q=a[c].q||[]).push(arguments)};a[g]||(a[g]=k.ak);b=e.createElement(h);b.async=1;b.src="//www.gstatic.com/wcm/loader.js";d=e.getElementsByTagName(h)[0];d.parentNode.insertBefore(b,d);a[f]=function(b,d,e){a[c](2,b,k,d,null,new Date,e)};a[f]()})(window,document,"_googWcmImpl","_googWcmGet","_googWcmAk","script");

1234 567 8901
</script>

The tags are for just phone numbers only, is there a way to add javascript around them?

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

How are you adding the phone number(s) to your page?

At the moment we have the tag

<?php perch_content('Phone Number'); ?> 

but to wrap the script around this just results in the phone number disappearing altogether

We also have a phone number field in

 <?php perch_content('Footer Contact Info'); ?>
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

but to wrap the script around this just results in the phone number disappearing altogether

Surrounding plain content with <script> tags doesn't work. There are various ways of adding content to your page with Javascript, but this isn't one of them.

I think the script finds the number on the page for you. So you may have the number some where on your page <span>1234 567 8901</span> and the script will find it and do whatever tracking wizardry it's supposed to do.

I'd suggest reading the Adwords instructions. On step 2 of the instructions here it explains how to add your tracking tag to your website.

For example, if this is what you need to output to the browser:

<html>
<head>
<title>Page Title</title>
<script type="text/javascript">
(function(a,e,c,f,g,h,b,d){var k={ak:"Anumber",cl:"Acode",autoreplace:"1234 567 8901"};a[c]=a[c]||function(){(a[c].q=a[c].q||[]).push(arguments)};a[g]||(a[g]=k.ak);b=e.createElement(h);b.async=1;b.src="//www.gstatic.com/wcm/loader.js";d=e.getElementsByTagName(h)[0];d.parentNode.insertBefore(b,d);a[f]=function(b,d,e){a[c](2,b,k,d,null,new Date,e)};a[f]()})(window,document,"_googWcmImpl","_googWcmGet","_googWcmAk","script");
</script> 
</head>

<body>
<div>1234 567 8901</div>
</body>

</html>

You might do this:

<html>
<head>
<title>Page Title</title>
<?php perch_content('Adwords'); ?> 
</head>

<body>
<?php perch_content('Footer Contact Info'); ?>
</body>

</html>

Hope this helps!

hi Adwords to one side (it turned out to just be Analytics code, which I have now added). Its just the script surrounding the phone number that is my problem now.

I have added the script to the head section as you suggested and asked them to test the page to see if it works.

I shall let you know.

Hi I checked with the Ad agency and am please to say that its all working fine.

Thanks Hussein, Jonathon and Drew for your help