0

I have an unsubpage that is displayed when someone clicks unsub in the email.

I want to resub on click with a button on the page - the below code is not working - can anyone inform me why? I have some basic Javascript knowledge and thought this would be simple

<script>


    Platform.Load("core","1");
    
    
    var subKey = Request.GetQueryStringParameter("sfmc_key");
    var btn = document.querySelector('#btn')
      var subscriber = {"Status": "Active"};
      var subObj = Subscriber.Init("subKey");
    btn.addEventListener('click',function(){
    
        var status = subObj.Update(subscriber);
        Platform.Response.Redirect("http://www.example.com");
        alert('hey')
    })
    
    
    
    </script>
5
  • 1
    You are mixing clientside and serverside javascript... So yes, this will never work. You should implement your SSJS in a JSON code resource, and call it from your frontend JS code. Aug 2 at 9:51
  • You can follow this example on how to create SSJS code to change status of the subscriber to active Aug 2 at 10:20
  • Thanks Lukas, Iactually found the above article but it had code var myList = List.Init("myList"); var status = myList.Subscribers.Update("mySubscriberKey","Active"); I want to resubscribe them in all subscribers, not a specific list - does mylist target allsubscribers? Also I understand the difference between platform and core (sorta) - I want to redirect to a page saying "you have been resubscribed" - can I use this in conjunction with ampscript or SSJS as I understand if I use redirecto - it does not work because it is serverside?
    – GS65
    Aug 2 at 10:41
  • It sounds to me you have long way to go, just understanding the basics of SSJS vs CSJS. StackExchange is not meant to provide you with turnkey solutions based on requirements, but help you when you are stuck. However we do require some level of research on your part. Here are some more examples for you to follow: Working with lists in SSJS, Working with code resources Aug 2 at 10:55
  • Thanks I appreciate it!
    – GS65
    Aug 2 at 11:32

0

Your Answer

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

Browse other questions tagged or ask your own question.