Beyond Triggered Campaigns: From MCP to SFMC data sync techniques

 

This blog post is about methods to integrate data from MCP (Marketing Cloud Platform) into Salesforce Marketing Cloud (SFMC). We'll explore three OOB approaches and a custom solution for writing data from sitemap directly to a SFMC data extension.


1. Triggered Campaigns in Journey Builder:

A straightforward method for integration involves leveraging Triggered Campaigns in MCP. By selecting user attributes and ensuring alignment with field names in the respective Marketing Cloud Journey data extension, we can send data to the Journey Builder journey.


2. Manually export a segment and import it into data extension. 

For one time or ad hoc requirements, marketers can manually export a segment from MCP and import it into a data extension within SFMC.

3. Using Segment File Exporter gear 

The Segment File Exporter Gear offers an automated solution for exporting segments in MCP. you can Set up a nightly feed or a one-time export of segments to the Personalization SFTP. MC personalization SFTP can be configured as external SFTP in SFMC from where the file can be automatically imported via automation.

4. Sitemap updating SFMC DE

 The process involves making a POST request from Sitemap to a Cloud Page, which then reads and inserts the data into a specified SFMC Data Extension.


JavaScript Code for Making POST Request:

The first step in this integration process is to make a POST request to a Cloud Page, sending the data from MCP Sitemap. Below is a JavaScript code snippet that accomplishes this task:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function postData(value1, value2) {

  // Define the URL to which you want to send the POST request

  const url = 'https://cloud.e.llflooring.com/MCPtoDE';



  // Define the data you want to send in the request body

  const data = {

    Customer_ID: value1,

    Email: value2

  };



  // Make the POST request using the fetch API

  return fetch(url, {

    method: 'POST',

    headers: {

      'Content-Type': 'application/json', // Specify the content type if sending JSON data

      // Add any other headers if needed

    },

    body: JSON.stringify(data) // Convert data to JSON string

  })

    .then(response => {

      if (!response.ok) {

        throw new Error('Network response was not ok');

      }

      return response.json(); // Parse the response JSON

    })

    .then(responseData => {

      // Handle the successful response here

      console.log('Response:', responseData);

      return responseData; // Return the parsed response data

    })

    .catch(error => {

      // Handle errors here

      console.error('Error:', error);

      throw error; // Propagate the error for further handling

    });

}


This code sends a POST request to a specified URL with MCP Sitemap data in JSON format.


Cloud Page Server-Side JavaScript (SSJS) to Process Data:

The Cloud Page, acting as the endpoint for the POST request, utilizes Server-Side JavaScript (SSJS) to process and insert the received data into an SFMC Data Extension. Here's a sample SSJS code snippet:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<script runat="server">

  // Load the required core library with version 1.1.1

  Platform.Load("core", "1.1.1");

  HTTPHeader.SetValue("Access-Control-Allow-Methods", "POST");

  HTTPHeader.SetValue("Access-Control-Allow-Origin", "*");



  try {

    // Retrieve the raw post data from the HTTP request

    var postData = Platform.Request.GetPostData();



    // Parse the received JSON data into a JavaScript object

    var jsonData = Platform.Function.ParseJSON(postData);



    // Extract values from the JSON object

    var Customer_ID = jsonData.Customer_ID;

    var Email = jsonData.Email;



    // Check for null or blank values before inserting into the Data Extension

    if (Customer_ID !== null && Customer_ID !== "" && Email !== null && Email !== "") {

      // Insert data into the "Sravan_test" Data Extension with specified fields

      var rows = Platform.Function.InsertData("Sravan_test", ["Customer_ID", "Email"], [Customer_ID, Email]);



      // Optionally, log a success message to indicate successful data insertion

      Write("Data inserted successfully!");

    } else {

      // Log an error message if null or blank values are found, and data is not inserted

      Write("Error: Null or blank values found. Data not inserted.");

    }

  } catch (e) {

    // Handle any errors that may occur during processing and log an error message

    Write("Error: " + e.message);

  }

</script>

No comments:

Post a Comment

Powered by Blogger.