简体   繁体   中英

piwik not working in HTTPS

I install piwik on sub domain analytics.mydomain.com/piwik [other VPS], and add javascript code in head tag in HTML on my website [HTTPS].

I worked laravel 5.3 framework.

This code:

<!-- Analytics Code -->
<script type="text/javascript">
    var _paq = _paq || [];
    // tracker methods like "setCustomDimension" should be called before "trackPageView"
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function() {
        var u="//analytics.mydomain.com/piwik/";
        _paq.push(['setTrackerUrl', u+'piwik.php']);
        _paq.push(['setSiteId', '1']);
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
    })();
</script>
<!-- End Analytics Code -->

This code working in localhost but not work on the server.

My website just working with HTTPS .

How to issue?

If the page is HTTPS, all assets - images, CSS, JavaScript, etc. - must also be HTTPS in modern browsers. Attempts to include HTTP assets will fail with a "mixed content" error.

You will need an SSL certificate for analytics.mydomain.com .

I ran into a similar issue awhile back. Forcing the url to https like below (in line 8) fixed it for me. I can't promise it will work for you, but it is worth a try.

<!-- Analytics Code -->
<script type="text/javascript">
    var _paq = _paq || [];
    // tracker methods like "setCustomDimension" should be called before "trackPageView"
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function() {
        var u="https://analytics.mydomain.com/piwik/";
        _paq.push(['setTrackerUrl', u+'piwik.php']);
        _paq.push(['setSiteId', '1']);
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
    })();
</script>
<!-- End Analytics Code -->

Your comment suggests you don't have SSL on analytics.mydomain.com , which means you need to force the code to not use HTTPS:

<!-- Analytics Code -->
<script type="text/javascript">
    var _paq = _paq || [];
    // tracker methods like "setCustomDimension" should be called before "trackPageView"
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function() {
        var u="http://analytics.mydomain.com/piwik/";
        _paq.push(['setTrackerUrl', u+'piwik.php']);
        _paq.push(['setSiteId', '1']);
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
    })();
</script>
<!-- End Analytics Code -->

When you use protocol-relative URLs (like // without http: or http: ), it tells the browser to call Piwik with the same protocol that the original page is in. If you don't have SSL on the Piwik server, it can't receive HTTPS requests (it will give a certificate error if it's even running on port 443).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM