Skip to content

Custom variables in iOS

Arnaud PICHERY edited this page Oct 19, 2018 · 1 revision

Custom variables are name-value pair tags that you can associate to your tracking events.

They allow you to define additional details about your events.

Variable scopes

As explained in the Concepts, each event logged in the WT1 system is related to:

  • A visitor : the client that visits the site (ie, the Web browser on the specific device used by the person)
  • A session : a period of time during which a visitor interacts with your site
  • The event itself (be it a page load or a custom event)

These three scopes can all accept custom variables.

For example:

  • At the visitor level, you might want to create a custom variable user_id to associate all events of this visitor to its user identifier in your internal database
  • At the session level, you might want to create a custom variable has_created_cart to indicate whether the visitor has created a cart during this session (you would set it to true when it happens). A session-scoped variable is automatically deleted when a new session starts for this user
  • At the event level, you will want to use variables to indicate the type and details of the event. For example:
    • type=video, name=video1 for a custom tracking event designed to log video views
    • type=refresh, value=item3 if the user refreshed the 3rd item on the page

Using custom variables

Visitor-scoped variables

The full list of visitor-scoped custom variables is set using

NSDictionary* myDictionary;
/* Set the variables in myDictionary */
[tracker updateVisitorParams:myDictionary];

NOTE: Updating the dictionary of variables only takes effect on any subsequent trackPage or trackEvent call.

Session-scoped variables

The full list of visitor-scoped custom variables is set using

NSDictionary* myDictionary;
/* Set the variables in myDictionary */
[tracker updateSessionParams:myDictionary];

NOTE: Updating the dictionary of variables only takes effect on any subsequent trackPage or trackEvent call.

Event-scoped variables

Event-scoped variables are set together with the trackPage or trackEvent calls.

NSDictionary* myDictionary;
/* Set the variables in myDictionary */
[tracker trackPage:@"mypage" withParams:myDictionary];
NSDictionary* myDictionary;
/* Set the variables in myDictionary */
[tracker trackEvent:@"mypage" withParams:myDictionary];