Loyalty Analytics

Overview

Embedded Analytics within SAP hybris Marketing Loyalty enables marketers or analysts to define their own set of KPIs to analyze how their loyalty program is performing. For example, there are KPIs to measure number of members who registered for the loyalty program, total revenue generated, loyalty points that have been accrued by members who have signed up for loyalty program and other loyalty KPIs.

The data will be read directly from loyalty micro services, and aggregated KPI results are achieved using Elastic Search capability of Hybris solution. Embedded analytics is currently supporting KPIs on loyalty data.

In YaaS Builder, the Analytics tab in SAP hybris Marketing Loyalty loads the Analytics dashboard that contains loyalty KPIs and charts.

The following loyalty KPIs are displayed:

  • Members - Total number of members who have signed up for the loyalty program
  • Member Activities - Total number of member activities
  • Member Revenue - Total revenue generated from loyalty program members in currency
  • Points Accrued - Total loyalty points accrued by loyalty program members
  • Points Redeemed - Total loyalty points redeemed by loyalty program members
  • Active Offers - Total offers active for the loyalty program
  • Redeemable Points - Total points available to redeem for the loyalty members

The following loyalty Charts are displayed:

  • Members by Tier (Pie Chart)
  • Members by Month / Qtr / Year per Tier
  • Member Activities by Month / Qtr / Year per Tier
  • Member Revenue by Month / Qtr / Year per Tier / Per currency

A marketer can filter these KPIs and charts based on the time period and tiers configured for the loyalty program. Only predefined KPIs are displayed. There is no option for marketers to create their own KPIs and charts. A marketer can hide or unhide KPIs based on their requirements.

For example, a marketer or Loyalty administrator in YaaS Builder can view the total loyalty points redeemed by loyalty program members, total points accrued by loyalty program, view total number of loyalty members and can also view this information using charts too.


API Reference

/queryMembers

/queryMembers

post

Provides loyalty analytics for members related data

Accepted scopes:

  • 'sap.loyanalytics_view' - Required to view Analytics

/queryMemberActivities

/queryMemberActivities

post

Provides loyalty analytics for member activities related data

Accepted scopes:

  • 'sap.loyanalytics_view' - Required to view Analytics

/queryOffers

/queryOffers

post

Provides loyalty analytics for offers related data

Accepted scopes:

  • 'sap.loyanalytics_view' - Required to view Analytics


Error Types

The error types will help you understand that the service has encountered an error and what you should do to actually get rid of the error.

The table presents all the error codes returned by the Loyalty Analytics service.

Error CodeDescription
NO_TENANT_HEADER_FOUNDhybris-tenant header is missing.
NO_BASE_CURRENCY_HEADER_FOUNDbase-currency header is missing.
NO_BODY_FOUNDAnalytics query is missing in request body.
INVALID_FILTER_QUERYFilter query passed in body, is invalid.
SOMETHING_WENT_WRONGGeneric error.

For more information about error codes, see the detailed error description for each API operation in API Reference. You can also check the standard error codes at API best practices.


Scopes

Scopes are strings that let you specify exactly what type of access you need to resources and operations in the Loyalty Analytics service.

You must provide a proper scope that enables users to perform certain operations. The scopes should be granted in an access token from OAuth 2.0 service. For more information about the authorization and authentication used in hybris services, and also about the scopes in general, see: Authorization Scopes

The table presents all the scopes supported by the Loyalty Analytics service.

ScopeDescription
sap.loyanalytics_viewUse this scope to view KPI or Chart.


Headers

Loyalty Analytics service can provide analytics based on currency value as well, for example, total revenue in USD, Euro etc. Similarly, other headers are required which are listed in below table:

HeaderDescriptionPossible ValuesDefault Value
base-currencyThe currency by which you want to accumulate your analytics response with.USD, EUR, AUD, BGN, BRL, CAD, CHF, CNY, CZK, DKK, GBP, HKD, HRK, HUF, IDR, ILS, INR, JPY, KRW, MXN, MYR, NOK, NZD, PHP, PLN, RON, RUB, SEK, SGD, THB, TRY, ZARUSD


Perform get and post Operation for Analytics service

Introduction

With the Loyalty Analytics service, you can do all the necessary operations to perform analytics related tasks. To perform the basic operations supported by the Analytics service, you need to be authorized. This is achieved through the header that carries the correct access token. The examples in this tutorial will lead you through those operations, showing what you need to provide to the methods, and what you get in return.

clientId = 'ICqjWvu41eUQQorT8SWAFwsnGWtIw5XC';
clientSecret = 'pMf1q4yjL7X4v28Z';
tenant = 'saploytest';
client = 'saploytest.apinotebooktutorialtest';
scopesRequired = 'hybris.tenant='+tenant+' sap.loycore_view sap.loycore_manage sap.loyanalytics_view';
token = '523-44f9feb2-e18c-4fc5-a0fa-c8e3e60126df';

Get access token

To perform any operations with a specific service, you always need an access token. For this purpose, create an API Client for the oAuth2 service:

API.createClient('oAuth2Service',
'/services/oauth2/v1/api.raml');

Now get the token:

AccessToken = oAuth2Service.token.post({
  'client_id' : clientId,
  'client_secret': clientSecret,
  'grant_type' : 'client_credentials',
  'token_type': 'Bearer',
  'scope': scopesRequired
});


access_token = AccessToken.body.access_token;

Create API client for Loyalty Analytics service

API.createClient('AnalyticsService',
'https://devportal.stage.yaas.io/services/loyaltyanalytics/v1/api.raml');

Create a Analytics object

Mentioned below are the default values from a test project. Replace the payload with proper values from your project.


members_count = AnalyticsService.queryMembers.post({
        "query":{
            "size":0,
            "query":{
                "filtered":{
                    "filter":{
                        "bool":{
                            "should":[

                            ],
                            "must":[

                            ],
                            "must_not":[

                            ]
                        }
                    }
                }
            },
            "aggs":{
                "total_members":{
                    "value_count":{
                        "field":"memberId"
                    }
                }
            }
        },
        "filters":{
            "dataMeta":{
                "for":"AGGS",
                "type":"SIMPLE"
            },
            "tiers":{
                "project":{
                    "field":"tierId",
                    "nested":false
                },
                "values":[

                ]
            },
            "date":{
                "project":{
                    "single":{
                        "field":"metadata.createdAt"
                    }
                },
                "year":[

                ],
                "month":[

                ]
            }
        }
    }, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )
"Total No. of Members: " + members_count.body.value;

member_activities_count = AnalyticsService.queryMemberActivities.post({
        "query":{
            "size":0,
            "query":{
                "filtered":{
                    "filter":{
                        "bool":{
                            "should":[

                            ],
                            "must":[

                            ],
                            "must_not":[

                            ]
                        }
                    }
                }
            },
            "aggs":{
                "total_member_activities":{
                    "value_count":{
                        "field":"memberActivityId"
                    }
                }
            }
        },
        "filters":{
            "dataMeta":{
                "for":"AGGS",
                "type":"SIMPLE"
            },
            "tiers":{
                "project":{
                    "field":"tierId",
                    "nested":false
                },
                "values":[

                ]
            },
            "date":{
                "project":{
                    "single":{
                        "field":"metadata.createdAt"
                    }
                },
                "year":[

                ],
                "month":[

                ]
            }
        }
    }, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )
"Total No. of Member Activities: " + member_activities_count.body.value;

offers_count = AnalyticsService.queryOffers.post({
        "query":{
            "size":0,
            "query":{
                "filtered":{
                    "filter":{
                        "bool":{
                            "should":[

                            ],
                            "must":[
                                {
                                    "term":{
                                        "offerStatus":"active"
                                    }
                                }
                            ],
                            "must_not":[

                            ]
                        }
                    }
                }
            },
            "aggs":{
                "total_active_offers":{
                    "value_count":{
                        "field":"offerId"
                    }
                }
            }
        },
        "filters":{
            "dataMeta":{
                "for":"AGGS",
                "type":"SIMPLE"
            },
            "tiers":{
                "project":{
                    "field":"tierId",
                    "nested":false
                },
                "values":[

                ]
            },
            "date":{
                "project":{
                    "multi":{
                        "from":"validFrom",
                        "to":"validTo"
                    }
                },
                "year":[

                ],
                "month":[

                ]
            }
        }
    }, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )
"Total No. of Offers: " + offers_count.body.value;


  • Send feedback

    If you find any information that is unclear or incorrect, please let us know so that we can improve the Dev Portal content.

  • Get Help

    Use our private help channel. Receive updates over email and contact our specialists directly.

  • hybris Experts

    If you need more information about this topic, visit hybris Experts to post your own question and interact with our community and experts.