1

Tracking data are collected in javascript while browsing the website. I'd like to save them into a data extension sitting in marketing cloud.

These are non-identifiable personal data.

I was thinking the webpage could call a javascript sitting in marketing cloud as follows:

<script src="https://pub.sx.exacttarget.com/xxxxxxxxxx?a=1111&b=22222"></script>

The javascript sitting in marketing cloud could get these 2 parameters a and b to store them into a data extension. It seems SSJS is not possible in cloud pages. Am I thinking in the proper way?

Thank you in advance

2

First of all: SSJS is available in Cloud Pages, so this is not a limitation. Secondly, you must be aware that each execution/page view of a Cloud Page results in one SuperMessage being consumed. If you plan on implementing this on a website with millions of page view monthly, you will run out of SuperMessages before sending any emails based on data collected.

I will advise you to utilise AmpScript instead of SSJS, and a JS Code Resource, instead of a Cloud Page, as executions of Code Resources don't consume SuperMessages

The Code Resource can be built quite simple:

%%[
SET @a = RequestParameter('a')
SET @b = RequestParameter('b')
SET @currentSystemTime = NOW()
SET @insertCount = InsertData('WebLog','id',GUID(),'a',@a,'b',@b,'timestamp',SystemDateToLocalDate(@currentSystemTime))
IF @insertCount > 0 THEN
Output(Concat("Success - ", @insertCount))
ELSE
Output(Concat("Error - ", @firstName))
ENDIF
]%%

I will also recommend configuring appropriate data retention policy, to avoid your data extension to grow uncontrollably.

4
  • Lukas, Fantastic! thanks! – Philippe Mar 4 at 17:11
  • Just to put my own note, using SSJS is a very viable option and depending on use case, it can be preferrable to AMPscript depending on the complexity or expected output. I find that 9 out of 10 times using SSJS on a Cloudpage or Code Resource is a better solution - but again personal preference. I just wanted to make sure to note the viability of SSJS as it tends to get a bad rap at times despite it being a powerful and versatile language in SFMC. – Gortonington Mar 4 at 19:42
  • 1
    Fully agree with you @Gortonington. However, I find AmpScript better suited for “entry level” development in SFMC - hence my first choice for many SFSE answers. – Lukas Lunow Mar 4 at 20:11
  • Absolutely @LukasLunow. I apologize for inserting a more PSA type comment on your answer. I just like to advocate for SSJS as it is an under-appreciated language. – Gortonington Mar 4 at 20:40

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.