Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Custom Meta Tags - Get Value


Reply


5 Posts   2880 Views

Avatar
steve_nyhof

Community Member, 224 Posts

23 October 2009 at 10:05am

Edited: 23/10/2009 10:09am

I have setup a test page to get this to work... This code works fine - give me the result I want.
The script gets the content of the meta tag called tracking.
<meta name="tracking" content="test12" /> I can enter this into the custom meta tag field.
http://businesswithsteve.com/1.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="tracking" content="test12" />
<script language="JavaScript">
function getTracking() {
var metas = document.getElementsByTagName('meta');
var i;
for (i = 0; i < metas.length; i++)
if (metas.getAttribute('name') == "tracking")
break;
var getVar = metas.getAttribute('content');
alert(getVar);
}
getTracking();
</script>

</head>

<body>
<!--BEGIN SNE CODE-->
<script language="JavaScript">
//var track = ('test');
document.write(checkTracking);

</script>
<!--END SNE CODE-->
</body>
</html>

----------------------------

However, on SS I can not get it to work... This is on my main page in the head...
Again it is looking for the the content from the meta name "tracking"
<meta name="tracking" content="test12" /> (entered into the custom SS meta tag field)

In the head...

<script language="JavaScript">
function getTracking() {
var metas = document.getElementsByTagName('meta');
var i;
for (i = 0; i < metas.length; i++)
if (metas.getAttribute('name') == "tracking")
break;
var getVar = metas.getAttribute('content');
// alert(getVar);
}
getTracking();
</script>

------

In the body of my landing page...

<div class="typography">
   
      <div id="Content">
      
      <h2>$Title</h2>
   
      $Content

<script language="JavaScript">
//var getVar = ('test');
document.write(getVar);
</script>

      </div>

</div>

This is a landing page
http://businesswithsteve.com/online-home-business-opportunity/

Any ideas as to why SS is not passing this value down the page?

Avatar
dalesaurus

Community Member, 283 Posts

23 October 2009 at 4:36pm

Edited: 23/10/2009 4:37pm

Have you tried moving your javascript to a separate .js file and including it in your template? At that point you could use jQuery for some assurance that it will get picked up and rewritten in your body.

Also if you are just using the WYSIWYG editor in the CMS, it has a tendency to strip out and reformat 90% of what you put in it...which can be quite frustrating...

Avatar
steve_nyhof

Community Member, 224 Posts

24 October 2009 at 1:21am

I have been able to get it working on a stand alone .php or .html file. The code I posted first is wrong. Here is the new code...
Also, I am adding this into the Layout>LandingPage.ss file... A special page that has this info in it.
Like I say, this same code works on a stand a lone page, put not in SS.
I have built many types of pages using this system below. People can still enter info into the editor, but other info is hard coded into the page below or above. And no, I am not entering the code into the editor - tried that a long time ago :)

<div class="typography">
   
      <div id="Content">
      
      <h1>$Title</h1>
   
      $Content
      
      

<!--START EXIT POPUP -->
<script language="JavaScript" type="text/javascript" src="http://oneyearplan.net/snyhof/zmasterT/expop/landing.js.php?id=10113"></script>
<!--END EXIT POPUP -->
<!--BEGIN FORM CODE -->
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr><td>&nbsp;</td>
<td width="400">
<table width="100%" height="300" border="0" cellpadding="0" cellspacing="20" style="background-color:#FAF8E4; border:#999999 dashed 1px;">
<tr>
<td colspan="3"><h1 align="center">Entrepreneurs Wanted</h1>
<p align="center">There is an entrepreneur in all of us. Come join us and learn how to unlock yours. Let&rsquo;s do this together! </p>
<p align="center">We're global, though <b>United States</b> is one of our key growth areas right now!</p></td>
</tr>
<tr>
<td><img src="../../../themes/site/images/blank.gif" width="50" height="1"></td>
<td><form method="post" action="http://www.aweber.com/scripts/addlead.pl"><input type="hidden" name="unit" value="sne_ccp_leads">
<input type="hidden" name="custom Url" value="oneyearplan.net/snyhof">
<input type="hidden" name="redirect" value="http://oneyearplan.net/snyhof/redirect.php"> <!--HANDLES LEADS & REDIRECTS-->
<input type="hidden" name="meta_redirect_onlist" value="http://oneyearplan.net/snyhof/redirect.php">

<script language="JavaScript" type="text/javascript">
function getTracking() {
var metas = document.getElementsByTagName('meta');
var i;
for (i = 0; i < metas.length; i++)
if (metas.getAttribute('name') == "tracking")
break;
var getVar = metas.getAttribute('content');
//alert(getVar);
return getVar;
}
var t = getTracking();

//urlquery=location.href.split("t=");
//if(urlquery[1]) {
// urlterms=urlquery[1].split("&");
// t = urlterms[0];
document.writeln('<INPUT TYPE="hidden" name="meta_adtracking" value="', t, '">');
document.writeln('<INPUT TYPE="hidden" name="custom t" value="', t, '">');

document.write('<scr'+'ipt language="JavaScript" src="http://oneyearplan.net/snyhof/zmaster/Scripts/visit.js.php?id=10113&t='+t+'"></scr'+'ipt>');
document.write('<scr'+'ipt language="JavaScript">\ndocument.writeln(\'<INPUT TYPE="hidden" name="custom Tracking" value="?v=\'+visit_id+\'">\');document.writeln(\'<INPUT TYPE="hidden" name="custom v" value="\'+visit_id+\'">\');\n</scr'+'ipt>');
</script>
<input type="hidden" name="custom member_id" value="10113">
<input type="hidden" name="custom landingpage" value="Custom">
<input type="hidden" name="meta_message" value="1">
<input type="hidden" name="meta_required" value="name,from">
<input type="hidden" name="meta_forward_vars" value="1">
<table width="266" align=center>
<tr><td align=right><font color="green"><b>First Name:</b></font></td><td>
<input type="text" name="name" value="" size="20"></td></tr>
<tr><td align=right><font color="green"><b>Email:</b></font></td><td>
<input type="text" name="from" value="" size="20"></td></tr>
<tr><td align=right><font color="green"><b>Phone</b> (optional):</font></td><td>
<input type="text" name="phone" value="" size="20"></td></tr>
<tr><td align="center" colspan="2"><div align="center">
<input type="submit" name="submit" value="Submit">
</div></td></tr>
</table>
</form>
<!--END FORM CODE --></td>
<td><img src="../../../themes/site/images/blank.gif" width="50" height="1"></td>
</tr>
<tr>
<td colspan="3"><p align="center"> Don't worry, you will be able to UNSUBSCRIBE at any time! </p>
<p align="center"> <a href="privacy-policy/" target="_blank">Privacy Assured</a>: Your email address is never shared with anyone. </p>

<p align="center"><strong>Fill out the form above to learn more about our mission to create <br>
100 millionaires by 2012.</strong></p></td>
</tr>
</table> </td>
<td>&nbsp;</td>
</tr>
</table>

</p>

<p>&nbsp;</p><p>&nbsp;</p><p>This information is not available to residents of Illinois, Wyoming, or South Dakota.</p>

<p>
Some members may make little or NO MONEY AT ALL with this program. The income examples depicted above are representative of some of the most successful participants in the program. They are not a guarantee of your income, nor are they typical of average program participants. Individual results will vary greatly, and in accordance to your input, determination, hard work,, and ability to follow directions. By using this website you are agreeing to our Income Disclaimer.</p>

   
      </div>

</div>

Avatar
dalesaurus

Community Member, 283 Posts

24 October 2009 at 9:56am

I just checked your page, and your JS is broken, nothing will work below line 244.

I very much recommend you move all your JS out of your template and into a separate .js file. Then you can use <% javascript(/path/to/file) %> in the template instead. That + Firebug will make your debugging far easier!

Avatar
steve_nyhof

Community Member, 224 Posts

31 October 2009 at 1:34pm

I'm doing this another way that is working