How to Use Geolocation Segmentation in SAP Marketing Cloud for FREE?

How to Use Geolocation Segmentation in SAP Marketing Cloud for FREE?

Written by: Jaroslav Lešťan, SAP Developer & Filip Žarnovický, CX Consultant

 

 

The segmentation tool is one of the most useful and most used applications in the SAP Marketing cloud. It is user-friendly, intuitive, fast, very capable, and contains various state-of-the-art gadgets. One of these is geolocation segmentation, so you can view all your contacts on the map and geo-filter them to create the ideal target audience. The aim of this article is not to describe functionality as such, but rather to focus on the technological side of geolocation data acquisition, because without it is just an empty map for you.

jak-vyuzivat-geolokacni-segmentaci-v-sap-marketing-cloud-zcela-zdarma  

But how to get this data? There are several solutions. Some need implementation of expensive licensing solutions, and some are available on the Web for free. We will now present the implementation of one of the free solutions.

 

There are some standard fields in SAP Cloud Marketing, such as LATITUDE and LONGITUDE, that are available for this purpose. In CDS view I_MKT_CONTACT (Marketing: Interaction Contact). Just add existing and newly created contacts with necessary GPS coordinates, and we can start segmenting.

 

For several years, SAP has offered the possibility of extending standard functionality through the implementation of the so-called BAdI, which is also available in the SAP Marketing Cloud. With BAdI, we can implement custom logic that will run when we create or change contact address information. The GEO location data itself can be retrieved, as already mentioned, using public APIs, based on the contact’s address data. Several providers offer the necessary APIs to get GPS coordinates. For our testing purposes, we will use OpenStreetMaps (OSM) service.

 

Browser API usage example:

jak-vyuzivat-geolokacni-segmentaci-v-sap-marketing-cloud-zcela-zdarma

  1. We will use the Custom Fields and Logic application available in the Extensibility section of the SAP Marketing Cloud to implement custom logic and call the necessary API. If you don’t see this app, make sure you have the required permissions.
    jak-vyuzivat-geolokacni-segmentaci-v-sap-marketing-cloud-zcela-zdarma
  2. In the application, select the Custom logic tab and use the + button to create a custom extension. For this purpose, it is necessary to choose the correct Busines context and BAdI description, which determines the place and time when our logic will be called.

jak-vyuzivat-geolokacni-segmentaci-v-sap-marketing-cloud-zcela-zdarma

  1. After setting up our extension, you will get to the implementation screen, where you can write your code with the help of ABAP for key users. Delete or modify the existing code according to your needs. For example, you can use the code below. To call and consume our API, SAP offers classes cl_ble_http_client and cl_ble_http_request that allow us to communicate with our selected public APIs. It will return the necessary GEO location data based on the contact address. A simplified solution is demonstrated by the implementation example below.

  jak-vyuzivat-geolokacni-segmentaci-v-sap-marketing-cloud-zcela-zdarma

 

 Code for copying:

 DATA:
lr_ic_root_new TYPE REF TO cuan_s_ce_ic_rt_badi.

DATA ls_body TYPE string.

” Create HTTP client to access the outbound service
DATA(lo_client) = cl_ble_http_client=>create(
communication_scenario = ‘YY1_API_GPS_OPENSTREETMAPS’
outbound_service = ‘YY1_APIOPENSTREETMAPS_REST’ ).

” Creation of the service request
DATA(lo_request) = cl_ble_http_request=>create(
” method that is used for the service call
)->set_method(
if_ble_http_request=>co_method-get).

* Process all updated interaction contacts.
LOOP AT new_contact_root REFERENCE INTO lr_ic_root_new.

DATA(lv_query) = ‘?format=json’ && ‘&street=’ && lr_ic_root_new->street && ‘&city=’ && lr_ic_root_new->city1 && ‘&country=’ && lr_ic_root_new->country.

” extend the URI by the specified query parameters
lo_request->set_resource_extension( lv_query ).
TRY.
” Send a request and receive a response.
DATA(lo_response) = lo_client->send( lo_request ).
CATCH cx_ble_http_exception.
lr_ic_root_new->yy1_gps_http_req_enh = ‘exception’.
ENDTRY.

” Get the body of the response.
ls_body = lo_response->get_body( ).
lr_ic_root_new->yy1_gps_http_res_1_enh = ls_body.

“Find the appropriate coordinates from the answer
lr_ic_root_new->latitude = substring_before( val = substring_after( val = ls_body sub = ‘”lat”:”‘) sub = ‘”‘ ).
lr_ic_root_new->longitude = substring_before( val = substring_after( val = ls_body sub = ‘”lon”:”‘) sub = ‘”‘ ).
ENDLOOP.

 

  1. To consume our public API within the SAP Marketing Cloud, we need to set up Communication Management:

a) We create a Communication Scenario with our Outbound service. An example of our service URL looks like this:
https://nominatim.openstreetmap.org/?format=json&street=XXXXXX&city=XXX&country=XX

b) We can set up a communication system without a communication user because our API does not require authentication,

c) after establishing the communication ARRANGEMENT, we test the correct communication of the system with our API using the Check connection button.

 

  1. After a successful setup, we can test our new logic. Create a new contact using the Contacts app. jak-vyuzivat-geolokacni-segmentaci-v-sap-marketing-cloud-zcela-zdarma
  2. Then check the obtained coordinates in the fields for a new contact, e.g., in the I_MKT_Contacts view.

 jak-vyuzivat-geolokacni-segmentaci-v-sap-marketing-cloud-zcela-zdarma

With Latitude and Longitude populated, nothing prevents you from going to the segmentation app and starting to create your audience using geolocation attributes. The method we described is free, but it has some performance limitations. Each provider has different settings, specifically OpenStreetMaps service has limits set to 1 request per second and a maximum of 10 000 requests per day. While this is sufficient for regular traffic, for bulk data import, it’s a bit of a problem but solvable.

jak-vyuzivat-geolokacni-segmentaci-v-sap-marketing-cloud-zcela-zdarma

With this comprehensive guide, you will get a working geolocation segmentation, but there is still plenty of room for improvement and adaptation to your specific requirements. That’s why Anodius offers the services of its experienced developers and consultants to help you grow your cloud solutions from SAP.


While this is a free way to get geolocation segmentation, the development and implementation of an extension itself can be costly for a company with insufficient developer capabilities. That’s why Anodius offers a simple and inexpensive solution that you can get at SAP App Center.


Experience matters.

 
Check the video below: