General Usage


For the first installation you can find the documentation here.


Using the API Widget you can register events that are dispatched by the widget.

The API Widget is included right after the body tag of your theme so please make sure to include any scripts that use the geolizr API below the following statement:

 

{% include 'geolizr-api' %}



You can register an event using the following function:


GeolizrAPI.addEventListener


Registers a callback function for a specific event.


GeolizrAPI.addEventListener([event], [callback]);


Parameters


event The event you'd like to listen to.


callback The function that is called whenever the event is dispatched.



Events


Here is a list of currently available events.


geolizr.geoData


Is dispatched as soon as the customer's geo data is available.

GeolizrAPI.addEventListener('geolizr.geoData', [callback]);

 

Callback parameters


geoData An object containing geo related informations:


{
  status: [success|false],
  as: "<provider id ex: ASxxxx Telecom GmbH>",
  city: "<city ex: Cologne>",
  country: {
    code: "<country-code ex: DE>",
    country": "<country-name ex: Germany>"
  },
  countryCode": "<country-iso-code ex: DE>",
  isp: "<Internet Service Provider ex: Telekom GmbH>",
  lat: <latitude ex: 50.9326>,
  lon: <longitude ex: 6.9342>,
  org: "<Organisation or Provider ex: Telekom GmbH>",
  query: "<ip adress ex: 87.78.185.249>",
  region: "<region-code ex: NW>",
  regionName: "<region-name: ex: North Rhine-Westphalia>",
  timezone: "<time-zone ex: Europe/Berlin>",
  zip: "<zip-code>",
  currencyCode: "<currency-code>",
  currency: {
    code: "<currency-code ex: EUR>"
  },
  countryName: "<country-name ex: Germany>"
}



Example


GeolizrAPI.addEventListener('geolizr.geoData', function(geoData) {
console.log(geoData);
});

Notifications

notification.show


Is dispatched whenever a notification is displayed.


GeolizrAPI.addEventListener('notification.show', [callback]);

 

Callback parameters


notification The notification:


{
  id: [notification id],
  dismissible: [true|false],
  rememberCloseState: [true|false],
  linkText: [text of the link],
  linkUrl: [URL of the link],
  message: [notification message],
  font: [list of fonts],
  backgroundColor: [background color],
  textColor: [text color],
  linkColor: [link color]
}




Example



GeolizrAPI.addEventListener('notification.show', function(notification) {
console.log(notification);
});



notification.resize

Is dispatched whenever a notification is resized.


GeolizrAPI.addEventListener('notification.resize', [callback]);

 

Callback parameters


notification The notification:


{
  id: [notification id],
  dismissible: [true|false],
  rememberCloseState: [true|false],
  linkText: [text of the link],
  linkUrl: [URL of the link],
  message: [notification message],
  font: [list of fonts],
  backgroundColor: [background color],
  textColor: [text color],
  linkColor: [link color]
}



notification.height The height of the notification.


Example


GeolizrAPI.addEventListener('notification.resize', function(notification) {
console.log(notification.notification);
console.log(notification.height);
});




notification.hide


Is dispatched whenever a notification is hidden.


Callback parameters


notification The notification:


{
  id: [notification id],
  dismissible: [true|false],
  rememberCloseState: [true|false],
  linkText: [text of the link],
  linkUrl: [URL of the link],
  message: [notification message],
  font: [list of fonts],
  backgroundColor: [background color],
  textColor: [text color],
  linkColor: [link color]
}



Example


GeolizrAPI.addEventListener('notification.hide', function(notification) {
console.log(notification);
});


Popups


popup.show


Is dispatched whenever a popup is displayed.


GeolizrAPI.addEventListener('popup.show', [callback]);

 

Callback parameters


popup The popup:


{
  id: [popup id],
  backgroundColor: [background color],
  pageBackgroundColor: [page background color],
  textColor: [text color],
  dismissible: [true|false],
  roundCorner: [true|false],
  rememberCloseState: [true|false],
  filterlistType: [none|blacklist|whitelist],
  filterlistUrls: [urls for the filter]
}




Example



GeolizrAPI.addEventListener('popup.show', function(popup) {
console.log(popup);
});



popup.resize

Is dispatched whenever a popup is resized.


GeolizrAPI.addEventListener('popup.resize', [callback]);

 

Callback parameters


popup The popup:


{
  id: [popup id],
  backgroundColor: [background color],
  pageBackgroundColor: [page background color],
  textColor: [text color],
  dismissible: [true|false],
  roundCorner: [true|false],
  rememberCloseState: [true|false],
  filterlistType: [none|blacklist|whitelist],
  filterlistUrls: [urls for the filter]
}




Example



GeolizrAPI.addEventListener('popup.show', function(popup) {
console.log(popup);
});



popup.hide


Is dispatched whenever a notification is hidden.



Callback parameters


popup The popup:


{
  id: "[popup id]",
  backgroundColor: "[background color]",
  pageBackgroundColor: "[page background color]",
  textColor: "[text color]",
  dismissible: "[true|false]",
  roundCorner: "[true|false]",
  rememberCloseState: "[true|false]",
  filterlistType: "[none|blacklist|whitelist]",
  filterlistUrls: "[urls for the filter]"
}




Example



GeolizrAPI.addEventListener('popup.show', function(popup) {
console.log(popup);
});


Redirects


redirect.executed


Is dispatched whenever the redirects are configured but not executed.


Callback parameters


redirectResult The result of the redirect.


{
     code: [rejected code],
     message: [rejected Message],
     redirect: {
         id: [redirect id],
         filterlistType: [none|blacklist|whitelist],
         filerlistUrls: [urls for the filter],
         redirectIgnoreReferrers: [urls for ignored referrers],
         redirectUrl: [target URL for the redirect]
     }
}


Codes and Messages


CodeMessage / Description
200<empty string> / No error - should not executed
904"Filter blocks the Redirect"
905"Referrer ... blocks the redirect"
906"Destination and current URL are the same"


Example


GeolizrAPI.addEventListener('redirect.notExecuted', function(result) {
  console.log(result);
});




Currency Converter


currency.change


Is dispatched whenever the currency has changed.


Callback parameters


currency The currency code.


Example


GeolizrAPI.addEventListener('currency.change', function(currency) {
console.log(currency);
});


currency.api


Is dispatched as soon as the currency api is available.


Callback parameters


api.switchCurrency A function that can be called to switch the currency.


api.getCurrency A function that returns the currently selected currency.


Example


GeolizrAPI.addEventListener('currency.api', function(api) {
api.switchCurrency('USD') // switches the currency to USD;
console.log(api.getCurrency());
});