Hybrid apps, visitor stitching and Visitor ID Service

17 Aug 2015 » Mobile

The classical problem of how to make sure that, in hybrid apps, the journey is not broken when transitioning from the native app to the embedded browser, is well known and it has been solved a long time ago. My colleague Carl Sandquist wrote a great post in the official Adobe blog some time ago about how to stitch visitors in hybrid apps. Two years later I still reference it to my customers. I recommend that, before you proceed with the rest of this post, you read it.

However, the aforementioned blog post does not cover the Visitor ID Service. It is still rarely used in mobile apps, but I am sure this will change as Web analysts use features like Customer Attributes.

Mobile SDKs currently support the Visitor ID service. It is very easy to enable: just add your Adobe Marketing Cloud Org ID in the ADBMobileConfig.json configuration file:

"marketingCloud" : {
    "org": "YOUR-MCORG-ID@AdobeOrg"

Now, the problem we face in hybrid apps is how to send the unique Visitor ID that has been given to the app, to the mobile web. I have not found anywhere any documentation about it, so I will attempt to explain it.

The first step is to retrieve all the possible IDs that may have been used. This is important as, during app upgrades, you do not want to create a new visitor and inflate your statistics. So, if an old value is still available, we should continue using it.

String mid = Visitor.getMarketingCloudId();
String aid = Analytics.getTrackingIdentifier();
String vid = Config.getUserIdentifier();

The next step is exactly to create a URL with all the previous parameters; this value needs to be passed to the web in a query string parameter. For example:

String url = "https://www.mobiledomain.com/index.php?mid=" + mid + "&aid=" + aid + "&vid=" + vid;

Moving to the web, the code becomes more complex, as there are various variables that might need to be set. In the s_code, outside of the doPlugins section, you need to add the following code:

if (typeof Visitor !== "undefined") {
 s.visitor = Visitor.getInstance("YOUR-MCORG-ID@AdobeOrg");
s.getPersistQueryParamID=new Function("param",""
+"var s=this;var id=s.Util.getQueryParam(param);if(id){var d=new Date"
+"d,d);}if(!id){id=s.Util.cookieRead('app_'+param);}return id;");

if (s.visitor) {
 if (s.getPersistQueryParamID("aid")) {
s.visitorID = s.getPersistQueryParamID("vid");

A few notes about the previous piece of code:

  • As with the SDK configuration, you need to replace YOUR-MCORG-ID with your Adobe Marketing Cloud Org ID
  • I am assuming you are using the AppMeasurement library; if you are still in the old H s_code, remember to replace the s.Util functions with the equivalents in H s_code.
  • The Visitor API version needs to be 1.3 or above.

If you are using DTM,you should copy this code to the “Customize Page Code” section of the Adobe Analytics tool.


It must be noted that you must select “Before UI settings”.

Now, you should have a single journey in hybrid apps and use all the capabilities of the Marketing Cloud.

Related Posts