我希望能够将Google Analytics分析代码移动到该数据库中。
最初我会在模板中手动执行此操作:
<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')[0]; s.parentNode.insertBefore(ga, s);
})();
{/literal}
--></script>
如何执行以下操作,允许用户将自己的分析数据输入数据库
<script type="text/javascript"><!--
{literal}
{$portal.google_analytics}
{/literal}
--></script>
答案 0 :(得分:2)
<script type="text/javascript"><!--
{$portal.google_analytics}
--></script>
或者如果您只是想让他们输入他们的帐户:
<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>
或
<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>
答案 1 :(得分:1)
<?php
// assuming your Smarty object is $smarty
$smarty->assign('ga_id','UA-xxxxxx-x');
$smarty->display('ga.tpl');
?>
ga.tpl(请注意,两个 literal
块,中间有ga_id
:
<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>