21294 Posts in 5734 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1174 Views |
-
Script content getting stripped

31 October 2009 at 1:58pm
I have been doing quite fine with this. I have setup my LeftAndMain.php file by first adding in the script[scr|... to the end of the valid_elemants
I have also try 'valid_elements' => "*
- ", star...star
But SS keeps stripping half of this code for google website optimizer...
This is what I insert...<script type="text/javascript">
if(typeof(_gat)!='object')document.write('<sc'+'ript src="http'+
(document.location.protocol=='https:'?'s://ssl':'://www')+
'.google-analytics.com/ga.js"></sc'+'ript>')</script>
<script type="text/javascript">
try {
var gwoTracker=_gat._getTracker("UA-11120272-2");
gwoTracker._trackPageview("/2027641438/test");
}catch(err){}</script>SS strips it to this...
<script type="text/javascript"><!--
if(typeof(_gat)!='object')document.write('<sc'+'ript src="http'+
(document.location.protocol=='https:'?'s://ssl':'://www')+
'.google-analytics.com/ga.js"></sc'+'ript>')
// --></script>
<script type="text/javascript"></script>Removing the second script - try {...
Anyone have some ideas? I want this done on the page, not on the template.
I was wondering if I could add a second custom metadata field, and then a tag $CustomMeta2 right before the /body tag ???
- ", star...star
-
Re: Script content getting stripped

31 October 2009 at 5:09pm Last edited: 31 October 2009 5:09pm
Your second approach would work, but this seems like the third post I've replied to you saying you should move your JS into .js files then include them in templates instead of finding so many damned ways to hack around and not do it that way.
Seriously, I just did google analytics with js templates and it was a breeze to switch out code tracker codes/HTTPS, etc. If you'd like to know how to do this the easy way, tell me you'll stop this hackery!
-
Re: Script content getting stripped

31 October 2009 at 6:47pm Last edited: 31 October 2009 6:49pm
I promise to stop the hackery! But I just am not a programmer and need to get this project off the ground.
I was able to add a field into my metadata tab for a body script which works great and I'm moving forward. Now I do not need to add the head and body scripts into the editor.
One question I have is how to add spaces to my CustomBodyTags name... Custom Body Tags so it shows up nice on the Metadata tab area. Also, how can I make the field 5 rows high to look like the other Meta tag fields?
The reason I do not want to make templates is because I want to make many split pages, each require a different script code/id.
public static $db = array(
'CustomBodyTags' => 'HTMLText'
);public static $has_one = array(
"HeaderImage" => "Image"
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new ImageField("HeaderImage"));
$fields->addFieldToTab('Root.Content.Metadata', new TextField('CustomBodyTags'));
return $fields;
}}
-
Re: Script content getting stripped

31 October 2009 at 7:51pm
I got this figured out now too...
$fields->addFieldToTab("Root.Content.Metadata", new TextareaField("CustomBodyTags", "Custom Body Tags"));
Added the TextareaField and the , "Custom Body Tags" to get my spaces.
-
Re: Script content getting stripped

1 November 2009 at 8:03am Last edited: 1 November 2009 8:05am
Bravo, sir! Now here is how you do it with JS Templates:
1. Create a place to store your codes with your Pages, similar to what you did above, in Page.php
public static $db = array(
'GoogleTrackingCode' => 'Varchar(255)'
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Metadata', new TextField('GoogleTrackingCode'));
return $fields;
}2. Create a JS Template file, for this example: mysite/templates/javascript/ga.template.js
try { var pageTracker = _gat._getTracker("{$TrackCode}"); pageTracker._trackPageview(); } catch(err) {}
3. User Requirements to put your custom variables in your template, in Page.php
public function init() {
parent::init();
if( isset($_SERVER['SSL']) || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ) {
Requirements::javascript('https://ssl.google-analytics.com/ga.js');
} else {
Requirements::javascript('http://www.google-analytics.com/ga.js');
}$jsData = array('TrackCode' => $this->data()->GoogleTrackingCode );
Requirements::javascriptTemplate('mysite/templates/javascript/ga.template.js',$jsData);
}Now on a per page basis you can specify your tracking code. It isn't a 100% solution but it should be a good start to storing only what you need and using templates to consolidate code. Of course what you did is also perfectly OK, but I just want to reinforce the methods that exist as the creators intended.
| 1174 Views | ||
|
Page:
1
|
Go to Top |


