Phone Replacement Script without Body onload?

273 views
Skip to first unread message

Jeff C

unread,
Mar 16, 2018, 3:42:27 PM3/16/18
to AdWords Scripts Forum
I know this isn't API related but maybe since it's a developers forum, I'd have a better chance getting a solution?

When doing call tracking you can dynamically replace the phone number on a web page with the Google forwarding number.  It required adding an onload function to the body tag. The problem is, I'm using a Wordpress site so it's not straightforward but there are ways around that I know.  The REAL problem is I have a dozen pages all with different phone numbers that need to be replaced so I need to customize the script with the phone number to be replaced for that page.

So I tried this. I put the required code in the head:

  <script type="text/javascript">
		    var callback = function(formatted_number, mobile_number) {
		      var e = document.getElementById("number");
		      e.innerHTML = "";
		      e.appendChild(document.createTextNode(formatted_number));
		    };
  </script>

And then instead of using:

<body onload="_googWcmGet(callback, '0800-123-4567')">
		  <span id="number">0800-123-4567</span>
</body>

I'm using:

<body>
	  <span id="number">0800-123-4567</span>
<script type="text/javascript">

    window.onload = _googWcmGet(callback, '0800-123-4567');
</script>

It errors out with _googWcmGet being undefined.  Think this is due to my lack of knowledge of JS/DOM stuff and that I need to cal _googWcmGet outside the body tag some other way?

Adrian Catambay (AdWords Scripts Team)

unread,
Mar 19, 2018, 12:24:28 AM3/19/18
to AdWords Scripts Forum
Hello Jeff,

Since this is not specifically related to AdWords Scripts, you may consider referring to this discussion I found in Stackoverflow which seems to be the same as the issue you are experiencing.

I would suggest that you post a question in Stackoverflow for more generic Javascript concerns.

Thanks,
Adrian
AdWords Scripts Team
Reply all
Reply to author
Forward
0 new messages