Forum Discussion

snaffle's avatar
snaffle
Expert
11 years ago

Pass referrer url from page initilization script to custom component

Hi,

 

I'm trying to work out how to capture a referring url in the Page Initialization script and forward it on to a custom component.

 

At this stage I have the following code in the Page Initialization script where I'm trying to set the referrer as a session attribute:

 

<#assign referrerUrl = http.request.referrer />
${http.session.setAttribute("forwardUrl", referrerUrl)}

And in the custom component, trying to retrieve the information I have:

 

${http.session.attributes.name.get("forwardUrl", referrerUrl)}

 and all I get is "This widget could not be displayed."

 

This might be completely the wrong way to go about it so I'd love some suggestions or advice on how best to go about this.

 

Thanks

 

Nathan

    • snaffle's avatar
      snaffle
      Expert

      Hi Nathan,

      Thanks for the reply and the welcome :smileyhappy:

      Yes I have already tried just using ${http.request.referrer} in the custom component, which works fine if I'm just clicking a direct link to the page, but I probably didn't explain my problem fully.

      I'm trying to capture referrals from a particular domain that we're using in an advertising campaign and redirect them to a custom page before signup using the Page Initialization feature. I've got that part working fine with the following:

      <#if http.request.serverName?ends_with("domain.com") && page.name != "Forum-Access">     
      ${http.response.setRedirectUrl("${community.urls.tapestryPrefix}/custom/page/page-id/Forum-Access")} <#else> </#if>

      The problem is, I also need to capture the referring url as part of the project requirements and when using the redirect to the custom page, ${http.request.referrer} just returns "The widget could not be displayed".

      So I've figured that I need to capture the referrer as part of the Page Initialization script and forward it on to the custom component... and that's where I'm stuck at the moment.

      Any ideas would be greatly appreciated.

      Cheers

      • snaffle's avatar
        snaffle
        Expert

        So having stared at it for a while I realised that because I had the redirect in place what I actually needed was to get the http.request.url in to the session rather than the http.request.referrer

         

        So the following achieved the result I was after:

         

             <#assign referrerUrl = http.request.url />
             ${http.session.setAttribute("forwardUrl", referrerUrl)}

         

        and the original url that was clicked on was displayed on the custom component.