Tracking Visitors
  • 16 Apr 2020
  • 2 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Tracking Visitors

  • Dark
    Light
  • PDF

Article summary

Tracking visitors: mobile application to website

To track visitors from the mobile application to a website, you need to launch a URL from the native app while maintaining user and session information between the Webtrends SDK in the app and the Webtrends JavaScript tag on the target page.

The target page must be tagged with the Webtrends JavaScript tag, and the native app must implement the Webtrends Mobile Library for Android.

For more information, see the "Webtrends JavaScript Tag" documentation.

  1. Tag your site by adding the webtrends.id_receiver.js plug-in to the JavaScript tag configuration on the target page.

    window.webtrendsAsyncInit = function () {
            var dcs = new Webtrends.dcs().init({
                    dcsid: "<your_dcsid>",
                    timezone: "<your_timezone>",
                    plugins: { 
                            id_receiver: { 
                                    src: "//s.webtrends.com/js/webtrends.id_receiver.js"
                            }
                    }
            });
            dcs.track();
    }
    
    
  2. Open the website from your application, using the Webtrends helper method to load the URL. This appends user and session information to the URL that the JavaScript plug-in parses and uses for its configuration.

    Note

    This must be done from within a class that extends Context, such as an Activity or a Service.

    String url = "http://www.yourdomain.com/targetPage.html";
    WebtrendsDataCollector.getInstance().openURL(this, url);
    }
    

Tracking visitors: website to mobile application

The Webtrends 10.2 Javascript tag and the ID Broadcaster plug-in enable you to send visitor data from your website to your mobile application.

To track visitors from your website to your mobile application, you need:

For more information, see the "Webtrends JavaScript Tag" documentation.

  1. Tag the website with the Webtrends JavaScript tag, using the id_broadcaster plug-in. Visitor data is added to links that match a list of element IDs or a list of domains, matched against the href of the link.

  2. Set an Activity in your Android Application as "BROWSABLE" and define the rules for how that activity intercepts requests. To make an Activity browsable, create an Intent-Filter in your AndroidManifest.xml file, for the target Activity, with rules to define the schemas, hosts, paths, content-type, etc. For more information, see Intents and Intent Filters on the Android Developer Network. This code sample intercepts clicks from www.test.com/app.

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
         package="webtrends.android.com"
         android:versionCode="1"
         android:versionName="1.0" >
        <application
             android:debuggable="true"
             android:icon="@drawable/icon"
             android:label="@string/app_name" >
    
            <activity
                android:label="@string/app_name"
                android:name=".YourTestActivity" >
                <intent-filter >
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
    
                <intent-filter >
                    <data
                        android:host="www.test.com"
                        android:path="/app"
                        android:scheme="http" />
                    <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.BROWSABLE" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
    
  3. Tag the Android activity using one of these approaches:

    • Automatic tracking: If you're using WTApplication as a base class for your Application, no other action is required. The first time a visitor launches your application from a web link, the SDK will reset its visitor id and session info to match that used by the website tag.
    public class YourTestApplication extends WTApplication {
    ...
        @Override
        public void onCreate() 
        {
            super.onCreate();
            ...
    
    • Manual tracking: If you're using the manual approach to tracking with the Webtrends SDK, then you'll need to use the convenience method (setSesionInfo(Context) to extract the visitor data from the link.
    public class YourTestActivity extends Activity {
    ...
            @Override
            private void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    //Configure the WTDataCollector's Static values..
                    WTDataCollector.setApplication(this);
                 WTDataCollector wtDataCollector = WTDataCollector.getInstance();
                    // Track event that open from web page
                    Uri data = this.getIntent().getData();
                    wtDataCollector.setSessionInfo(this);
            }
            
    

Was this article helpful?