We’ve migrated our documentation to a new site, which means some URLs have changed.
Subscriptions

How to add a targetable Cookie after a Visitor clicks on an Element in the Offer Template?

Unlike the Set cookie action card in Composer, which sets the cookie when viewing an Offer template, the following steps will guide you on how to set a cookie when a visitor clicks on an element in the Offer template.

  1. In the Offer Template's code, you need to add an external event to the element(s) you'd like to track. Once set up, you will see the number of clicks on the element(s) in the Composer conversions report.

  2. In Composer, add a Run JS action card right below the Show Offer or Show Template action card. With the code below you will set the cookie.

    tp.push(["addHandler", "checkoutCustomEvent", function(event) {
      switch(event.eventName) {
        case "external-event-name":
          document.cookie = "_pc_cookie_name=true" + ";path=/";
          break;
      }
    }]);
    

    Please note, that you should change the external event name to the name you've set up in the Offer Template's code in step 1. Also, you can rename the cookie by changing the cookie_name. Both names should be self-explanatory, so you can recognize them later in the reports.

  3. If you'd like the cookie to expire, you can add use the following code instead of the one from the step 2:

    tp.push(["addHandler", "checkoutCustomEvent", function(event) {
      switch(event.eventName) {
        case "external-event-name":
      var currentDate = new Date(); 
          document.cookie = "_pc_cookie_name=true;expires=" + new Date(currentDate.getTime() + 
          7*24*60*60*1000).toGMTString() + ";path=/";
          break;
      }
    }]);
    

    This is an example of when the cookie expiration is set to 7 days. The expiration time is counted in milliseconds, so an expiration of {{7*24*60*60*1000}} means that the cookie expires in 7 days * 24 hours * 60 minutes * 60 seconds * 1000 milliseconds.

Last updated: