Custom object

 

Foreword

The SDK allows the addition of all sorts of information to the stc variable via dictionaries or JSON feeds. Custom objects can be added to any type of tagging, and can then be treated via the Data Manager tool.

 

Get off to a good start

Once your tag is initialised, you can add your custom objects to your hits.

If you want to use variables, be sure to import ATInternet, Tracker and CustomObject classes in your Activity.

 

Tagging

To add a custom object to your hits, the tracker, Screen, Gesture, Publisher and SelfPromotion objects expose a customObjects object possessing an add method. This method allows for the addition of a custom object that will be added to the next hit sent.

 

Tagging examples

  1. Tagging a screen with addition of a “simple” custom object
    package com.atinternet.atinternetdemo;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    import com.atinternet.tracker.ATInternet;
    import com.atinternet.tracker.Debugger;
    import com.atinternet.tracker.Tracker;
    
    import java.util.HashMap;
    
    
    public class MainActivity extends Activity {
    
        private Tracker tracker;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tracker = ATInternet.getInstance().getDefaultTracker();
        }
    
        @Override
        protected void onResume() {
            super.onResume();
            Screen s = tracker.Screens().add(this);
            s.CustomObjects().add(new HashMap<String, Object>() {{
                put("firstName", "John");
                put("name", "Doe");
                put("age", 26);
            }});
            s.sendView();
        }
    }

    JSON result in stc variable  :

    {
        "lifecycle": {
            "fl": 0,
            "fld": 20151014,
            "dsfl": 1,
            "flau": 0,
            "dslu": 0,
            "lc": 57,
            "lcsu": 0,
            "ldc": 9,
            "lwc": 57,
            "lmc": 57
        },
        "firstName": "John",
        "age": 26,
        "name": "Doe"
    }
  2. Tagging a screen with addition of a “complex” custom object
    package com.atinternet.atinternetdemo;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    import com.atinternet.tracker.ATInternet;
    import com.atinternet.tracker.Debugger;
    import com.atinternet.tracker.Tracker;
    
    import java.util.HashMap;
    
    
    public class MainActivity extends Activity {
    
        private Tracker tracker;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tracker = ATInternet.getInstance().getDefaultTracker();
        }
    
        @Override
        protected void onResume() {
            super.onResume();
            Screen s = tracker.Screens().add(this);
            s.CustomObjects().add(new HashMap<String, Object>() {{
                put("user", new HashMap<String, String>() {{
                    put("language", "en");
                    put("country", "US");
                    put("currency", "USD");
                }});
            }});
            s.sendView();
        }
    }

    JSON result in stc variable  :

    {
        "lifecycle": {
            "fl": 0,
            "fld": 20151014,
            "dsfl": 1,
            "flau": 0,
            "dslu": 0,
            "lc": 58,
            "lcsu": 0,
            "ldc": 10,
            "lwc": 58,
            "lmc": 58
        },
        "user": {
            "language": "en",
            "currency": "USD",
            "country": "US"
        }
    }
  3. Tagging navigation with the addition of a custom object
    package com.atinternet.atinternetdemo;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    import com.atinternet.tracker.ATInternet;
    import com.atinternet.tracker.Debugger;
    import com.atinternet.tracker.Tracker;
    
    import java.util.HashMap;
    
    
    public class MainActivity extends Activity {
    
        private Tracker tracker;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tracker = ATInternet.getInstance().getDefaultTracker();
        }
    
        @Override
        protected void onResume() {
            super.onResume();
            Gesture g = tracker.Gestures().add(this);
            g.CustomObjects().add(new HashMap<String, Object>() {{
                put("user", new HashMap<String, String>() {{
                    put("language", "en");
                    put("country", "US");
                    put("currency", "USD");
                }});
            }});
            g.sendNavigation();
        }
    }
  4. Tagging an ad with the addition of a custom object
    package com.atinternet.atinternetdemo;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    import com.atinternet.tracker.ATInternet;
    import com.atinternet.tracker.Debugger;
    import com.atinternet.tracker.Tracker;
    
    import java.util.HashMap;
    
    
    public class MainActivity extends Activity {
    
        private Tracker tracker;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tracker = ATInternet.getInstance().getDefaultTracker();
        }
    
        @Override
        protected void onResume() {
            super.onResume();
            Publisher pub = tracker.Publishers().add("[ad1]");
            pub.CustomObjects().add(new HashMap<String, Object>() {{
                put("user", new HashMap<String, String>() {{
                    put("language", "en");
                    put("country", "US");
                    put("currency", "USD");
                }});
            }});
            pub.sendImpression();
        }
    }
 

CustomObject class

 

Properties

Name Type Default value Description
json String {} Gets or sets the object in JSON format
Was this post helpful?
Yes
No
Last update: 05/04/2018