3

I have a visualforce site, running the Google Analytics asynchronous tracker. So that a customer can log in, we have a redirect from the unsecure, branded site (www.something.com) to the company.secure.force.com domain.

Works fine, but breaks our Analytics source tracking (cookie set by custom domain can't be read by the cookie on secure.force.com). So we use the GA cross-domain tracking method _link('url').

Works for Chrome, but not for IE. In this, a controller is supplying the value of {https} based on a custom setting.

<script>
      var registerRedir = '{!https}';         
      _gaq.push(['_link', '{!https}']);              
      window.location.href = registerRedir;        

1

Just glancing here: https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSite

I think the cross-domain tracking is breaking because your actually not directing them to another top-level domain (secure.force.com is a sub-domain of force.com), and it seems they intended this for use in tracking sub-domains within the same space as a top-level domain, or two-top level domains. Not a top-level and the sub-level of another?

1
  • That's entirely possible, but doesn't explain the browser differences. In chrome, the link appends a whole bunch of query string to the URL, but IE just shows up with the URL. Aug 21 '12 at 12:52
1

I did get this one solved. 3 nasty steps, but the cookie stays on the visitor the entire time.

1) use a remote method for the login that returns the "frontdoor" url

@RemoteAction
    global static string RemoteLogin(string email, string password, string url){
        PageReference result = new PageReference('temp');
        try {
            result = Site.login(email, password, url);
            system.debug(result);
        }catch (exception e){
            return e.getMessage();
        }
        if (result!=null) {
            return result.getURL(); 
        } else {
            return 'login error';
        }
    }

2) use the normal GA push link method to get to your site login page (on the secure side). Could be a link or a button, or a redirect. In our case, we did a redirect. Make sure your GA script happens before the push method just in case.

<apex:outputpanel rendered="{!$Site.CurrentSiteUrl='http://www.yourCustomUrl.com/'}">
    <c:GoogleAnalyticsTrackingCodeScript />
    <script>
    _gaq.push(['_link', 'https://yourRealDomain.secure.force.com/SiteLogin']);
    </script>
</apex:outputpanel>

The "real content" of the login page is in another rendered tag that shows if you're already on the secure domain.

If you did this right, you'll see the page redirect and all the GA UTM_* cookies will be attached as url parameters.

Step 3: Call your remoting login method and parse what comes back

function Login(){
    var pagename = '{!$CurrentPage.Name}';
    if (pagename == 'SiteLogin') pagename='homepage';
    ControllerName.RemoteLogin($j("#email").val(),$j("#password").val(), '/'+pagename, function(result2, event){
        if (result2!='login error'){
            var decoded = result2.replace('amp;', '').replace('amp;', '').replace('amp;', '').replace('amp;', '').replace('amp;', '').replace('amp;', '').replace('amp;', '').replace('amp;', '');                                    
            _gaq.push(['_link', decoded]);
        } else{
            $j("#login_submit").button('reset');
            $j("#login_error").show();
            console.log(result2);
        }
    });

}

More on the GA push link method: https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSite

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.