I need to store the opens/clicks for a cloud page in a Data Extension. Can anyone please share some sample code for this?
Firstly, create a Data Extension containing fields you need to capture then use the AMPscript InsertData function to populate the required values into the DE fields.
In the example below, a Data Extension named 'Page Visits' includes two fields, Subscriber Key (text field) and Event Date (date field). There is no primary key on the DE.
Assumming a the Subscriber visits the page from an email link using the CloudPagesURL function, the Subscriber Key and the date (based on the Business Unit timezone) will be inserted into the Data Extension when the page loads.
%%[ InsertData('Page Visits','Subscriber Key', _subscriberKey, 'Event Date', SystemDateToLocalDate(Now())) ]%%