I want to be able to move the google analytics code into that database.
Originally I would manually do this inside of the template:
<script type="text/javascript"><!--
{literal}
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-19807844-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[开发者_JS百科0]; s.parentNode.insertBefore(ga, s);
})();
{/literal}
--></script>
How do I do something like below, that allows the user to enter into the database their own analytics
<script type="text/javascript"><!--
{literal}
{$portal.google_analytics}
{/literal}
--></script>
<script type="text/javascript"><!--
{$portal.google_analytics}
--></script>
or if you just want them to enter their Account:
<script type="text/javascript"><!--
var _gaq = _gaq || [];
_gaq.push(['_setAccount', {$portal.google_analytics_account}]);
_gaq.push(['_trackPageview']);
{literal}
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
{/literal}
--></script>
or
<script type="text/javascript"><!--
{literal}
var _gaq = _gaq || [];
_gaq.push(['_setAccount', {/literal}{$portal.google_analytics_account}{literal}]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
{/literal}
--></script>
<?php
// assuming your Smarty object is $smarty
$smarty->assign('ga_id','UA-xxxxxx-x');
$smarty->display('ga.tpl');
?>
ga.tpl (note that there are two literal
blocks, with the ga_id
in-between):
<script type="text/javascript"><!--
{literal}
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '{/literal}{$ga_id}{literal}']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ?
'https://ssl' : 'http://www') +
'.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
{/literal}
--></script>
精彩评论