OSCOMMERCE SUPPORT CALL 702-453-3332

 

Help - Search - Members - Calendar
Full Version: Google-analytics and SSL
osCommerce Community Support Forums > osCommerce Online Merchant v2.x > Tips and Tricks
germ
If you have google-analytics java script on your site, it will give you the "Do you want to display the nonsecure items?" popup if you install an SSL certificate.

Since Google doesn't index SSL pages, here's a way to get PHP to ignore the code when in SSL mode, and you won't get the nonsecure items popup:

CODE
<?php
if ( $request_type != 'SSL' ) {
?>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-xxxxxxx-x";
urchinTracker();
</script>
<?php
}
?>

Wrap the PHP code around your google-analytics script as shown above.
web-project
if you use new code of Google-analytics it will support the SSL - secure protocol.

CODE
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxx-x");
pageTracker._initData();
pageTracker._trackPageview();
</script>
germ
If the code isn't inserted properly, it can cause the Java Script error:

_gat is not defined

I've seen that on some sites.

I Google'd that error, and it said to check for extra spaces in the code.
germ
I found a fix for the _gat os not defined error:

CODE
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
if (typeof(_gat) == "object") {
  var pageTracker = _gat._getTracker("UA-xxxxx-x");
  pageTracker._initData();
  pageTracker._trackPageview();
}
</script>
NewBudda
How would I make the following Statcounter code "SSL Safe"?
I really have no idea about Javascript sad.gif
CODE
<!-- Start of StatCounter Code -->
<script type="text/javascript">
var sc_project=34XXX4;
var sc_invisible=1;
var sc_partition=38;
var sc_security="12eXXXc7";
</script>

<script type="text/javascript"

src="http://www.statcounter.com/counter/counter_xhtml.js"></script><noscript><div

class="statcounter"><a href="http://www.statcounter.com/free_invisible_web_tracker.html"

target="_blank"><img class="statcounter" src="http://c39.statcounter.com/34XXXX4/0/1XXX0c7/1/"

alt="free web tracker" ></a></div></noscript>
<!-- End of StatCounter Code -->


I believe that this code is in part responsibly for me "non-secure items" Messages.
germ
CODE
<?php
if ( $request_type != 'SSL' ) {
?>

<!-- Start of StatCounter Code -->
<script type="text/javascript">
var sc_project=34XXX4;
var sc_invisible=1;
var sc_partition=38;
var sc_security="12eXXXc7";
</script>

<script type="text/javascript"

src="http://www.statcounter.com/counter/counter_xhtml.js"></script><noscript><div

class="statcounter"><a href="http://www.statcounter.com/free_invisible_web_tracker.html"

target="_blank"><img class="statcounter" src="http://c39.statcounter.com/34XXXX4/0/1XXX0c7/1/"

alt="free web tracker" ></a></div></noscript>
<!-- End of StatCounter Code -->

<?php
}
?>
NewBudda
Thank you! That works great, but:
QUOTE
here's a way to get PHP to ignore the code when in SSL mode

Does that mean that I wont receive anymore Stats from the Pages that are requested in SSL?
germ
True.

No more stats from SSL pages.

But you really have little choice, unless they upgrade the code to work in SSL mode.
dub3325
awesome...works great germ, thanks....seems like google is still tracking my pages....lets hope i didnt break anything
jfo9696
I'm feeling sort of stupid here but what is Google-analytics?
khoking
I have google analytics code in my footer and have not experience the non-secure warning. Something wrong?

My site is at http://shashinki.com/shop/
germ
I don't want to rain on your parade, but I've looked at your HTML source and I don't see Google Analytics anywhere.....
blush.gif
gforster
Which file do you put your code in ?

I have tried in several places and although it tracks stats it never appears in between the body tags which is where I am it SHOULD go ?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.