0

I have a custom preference center built in CloudPages. Also have a separate code resource file (RetrieveMemberdata.js) which contains all my AMPScript. This file is invoked from CloudPage using tag as below. Below is the snippet from my CloudPage -

</style>
  %%[Set @subkey = _subscriberkey]%%
  <script type="text/javascript" src="http://cloud.homes.xyz.email/RetrieveMemberdata.js"></script>
</head>
<body class="typical ">

Now in the JS file (RetrieveMemberdata.js), I want to be able to access the value of this subscriberkey. Once I am able to obtain it, there is a lot of logic that will be executed using AMPScript in this file. I tried using the below but it doesn't work

var RetrievedInfo = {};
var RetrievedContactInfo = {};
var subskey= Variable.GetValue("@subkey");
%%[ 
VAR @email, @count, @IsValid, @IsContact
....
....
]%%

Help will be much appreciated

0

if the cloudpages is being loaded as a result of clicking on a link in an email you can use the cloudpagesurl(pageid) function to build the url link in the email and you can get the subscriberkey using the personalization string as below on cloudpages.

%%[
Set @subscriberkey = _subscriberkey

]%%
<script runat=server>
    Platform.Load("Core","1");
var subkey= Variable.GetValue("@subscriberkey");
Write("Your subscriber key = "+subkey);
</script>

Using CloudpagesURL function instead of the actual link in the email allows you to pass subscriber and send data e.g subscriberkey, emailaddress, jobid, listid etc..

https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/cloudpagesurl.htm

  • Thanks for that. I am using CloudpagesURL() in my email which opens up the preference center. Now from there, I need to pass the subscriberkey to the JS file that has all the AMPScript. How can I do that? – Maneesh Mar 8 at 20:50
  • I have updated the code in my answer, hope that helps – Finan Nazazi Mar 9 at 21:10
  • Really appreciate your help Finan but unfortunately it didn't work. I have tried to clarify my situation a little more in the original question. Can you advise please? – Maneesh Mar 10 at 18:17
  • 1
    if the code is all in Ampscript, I would store it in a content block and use the %%=ContentBlockbyKey("content_block_external_key")=%% function to load it where the js code is being called, instead of storing AmpScript codes in another js cloud page. – Finan Nazazi Mar 10 at 22:07

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.