Giter Site home page Giter Site logo

parcellab / parcellab-js-plugin Goto Github PK

View Code? Open in Web Editor NEW
8.0 13.0 2.0 3.64 MB

JavaScript plugin used to retrieve and display trackings from parcelLab on any given webpage.

Home Page: https://how.parcellab.works/docs/integration-quick-start/track-and-trace-page

JavaScript 94.04% HTML 0.82% SCSS 5.14%
ecommerce javascript-plugin deliveries parcels parcellab webpage courier prediction team-frontend

parcellab-js-plugin's Introduction

parcelLab JavaScript Plugin v3

v4 available on v4 branch.

parcelLab JS Plugin

Integrate parcelLab to your shop frontend (or any webpage). This plugin will fetch and display all important information of a given tracking and turn any webpage to a delivery status page.

Integrate delivery status page

Adding to your webpage

Just place the following snippet into the container you want the plugin to be rendered.

<div id="pl-trace"></div>

<script  type="text/javascript">
  (function (prcl) {/* Load parcelLab assets ... */
    if (window.ParcelLab) {return prcl();}function a() {var styles = document.createElement('link'); styles.rel = 'stylesheet'; styles.href = 'https://cdn.parcellab.com/css/v3/parcelLab.min.css'; document.getElementsByTagName('head')[0].appendChild(styles); }function b(cb) { var script = document.createElement('script'); script.async = true; script.src = 'https://cdn.parcellab.com/js/v3/parcelLab.min.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script); script.onload = cb; } a(); b(prcl);
  })(function () {/* ... plugin is ready to use: */
    var options = {};
    var pl = new ParcelLab('#pl-trace', options);
    pl.initialize();
    window._prcl = pl;
  });
</script>

This snippet will load the needed assets and render the parcelLab plugin into the div with the id "#pl-trace". If you want the plugin to be rendered to an other DOM node you just have to change the id in the snippet. Further you can customize the plugin by extending the options object (see below).

WARNING

If your webpage does not allow post hoc insertion of assets (scripts and stylesheets), you have to add the assets manually in the <header> part of your webpage.
A recent version of these scripts is always available at the parcelLab CDN:

  • <link href="https://cdn.parcellab.com/css/v3/parcelLab.min.css" rel="stylesheet">
  • <script src="https://cdn.parcellab.com/js/v3/parcelLab.min.js" charset="utf-8"></script>

Options

You can define options by passing an Object as second argument, when creating a new ParcelLab Object.

  <script type="text/javascript">
    ...
    var options = { rerouteButton: 'left', show_searchForm: 'true' };
    var parcelLab = new ParcelLab('#pl-trace', options);
    parcelLab.initialize();
    ...
  </script>

These are the available options:

  • styles: Boolean (false will disable the default css for custom styling)
  • customStyles: Object (see below)
  • rerouteButton: 'left' | 'right' - default is 'right' (defines where to render the reroute button if possible)
  • show_searchForm: Boolean (activates a search form, which will be rendered if tracking was not found or no trackingNo/orderNo was given, needs userId)
  • show_zipCodeInput: Boolean (activates the zip code field for the search form)
  • userId: String (alternative way to pass userId - instead of in url)
  • trackingNo: String (alternative way to pass trackingNo - instead of in url)
  • orderNo: String (alternative way to pass orderNo - instead of in url)
  • zip: String (alternative way to pass zip - instead of in url)
  • courier: String (alternative way to pass courier - instead of in url)
  • client: String (alternative way to pass courier - instead of in url)
  • selectedTrackingNo: String (alternative way to pass selectedTrackingNo - instead of in url)
  • show_note: String (renders a note box on top - useful for showing important information)
  • onRendered: Function (the plugin will run this function whenever it (re)renders)
  • icon_theme: 'xmas' | 'easter' (activates the themed icons ๐ŸŽ„/๐Ÿฐ)
  • customTranslations Object (see below)
  • lang: Language ISO code, if not provided, user browser language will be used. (It can be 2 letters code en or 4 en-us)

All options can also be set via URL search query.
Just drop the '#' from hex colors and/or encode as URI component if needed.
www.yourshop.com/tracking/page/path?trackingNo=xyz&courier=dhl-germany

Banner

The script can render an image banner link on the right, with these option parameters:

  • banner_image : String (url of image or 'instagram' for your latest instagram posting)
  • banner_link : String (url of link destination)

banner_link is optional if banner_image is 'instagram' where it defaults to your instagram page.

For a custom banner_image we recommend PNG or JPG with a ratio of 0.7 : 1, but any other format can be chosen as well. A recommended solution is 700 x 1000 px for optimal rendering on retina screens, with texts being at least 16px high.

โš  instagram banners are not enabled by default. ask our support if you want this feature.

โš  instagram banners require the u parameter with your userId to be present

Custom styling

You can customize the buttons and the boxes of the plugin by simply passing the Object 'customStyles' in the options.
Possible customStyle options:

options.customStyles = {
  borderColor: '#eeeeee', // sets border color for the boxes (default: #eeeeee)
  borderRadius: '4px', // sets the border radius for the boxes and buttons (default: 4px)
  buttonColor: '#333', // sets text color for buttons (default: #333)
  buttonBackground: '#e6e6e6', // sets background color for buttons (default: #e6e6e6)
  iconColor: '#000', // sets color for the status icons (default: #000)
  tabIconColor: '#000', // sets color for the order tab icons (default: buttonColor #333)
  activeTabIconColor: '#000', // sets color only for the active order tab icon (default: buttonColor #333)
  actionIconColor: '#000', // sets color only for the icons of the actionbox buttons
  margin: '0px 0px', // sets mnargin for #pl-main-box (default: 0px)
};

The customStyles attr can also be passed in via URL search query (without 'customStyles' parent key).
Just drop the '#' from hex colors and/or encode as URI component if needed.
For example www.versand-status.de/?trackingNo=...&borderRadius=2px&buttonColor=e6e6e6

โš ๏ธ If you need more customizing, use a custom stylesheet.

Hook onRendered

There is another option called onRendered which expects a function (state) with state being an object describing the pulled information:

var plRenderedHook = function (state) {
  // Do something with the DOM or the information
  console.log(state);
};

var parcelLab = new ParcelLab('#pl-trace', { onRendered: plRenderedHook });
parcelLab.initialize();

Custom styling example

In this example we will set the box and button border-radius to 0px and make the buttons black.

<script type="text/javascript">
  var custom = { borderRadius: '0px', buttonBackground: '#000000', buttonColor: '#fff' };

  var parcelLab = new ParcelLab('#pl-trace', { styles: true, customStyles: custom });
  parcelLab.initialize();
</script>

Without action box

If you want to use the plugin in a non-customer facing website (e.g. internal page for customer support), it is recommended to hide the action box like so:

<style> div#pl-action-box-container { display: none; } </style>

Custom translations

You can change the static plugin text parts with your own translations. Therefor just add the attribute customTranslations to options and fill with your custom texts. You can find the full list of texts, used by the plugin here. If you don't define a language in your customTranslations, the plugin will fallback to the original text, when rendered in this language.

Custom translations example

Lets change the texts for the search form:

  ...
  options.customTranslations = {
    de: {
      searchOrder: 'Bestellnummer eingeben', // translation for search input placeholder
      zip: 'PLZ eingeben', // translation for zip input placeholder
      search: 'Suche starten', // translation for search button text
    },
    en: {
      searchOrder: 'Type order number',
      zip: 'Type zip code',
      search: 'Start search',
    },
  }
  var parcelLab = new ParcelLab('#pl-trace', options);
  parcelLab.initialize();

Integrate delivery time prediction

Please note: Delivery time prediction is currently only supported for deliveries to Germany.

Adding to your webpage

Same as above.

Initializing

After adding the script, there will be a new ParcelLabPrediction class in the global scope. This can also just be initialized, but more options are required for the script to work. Following parameters are required to be supplied in the options object:

  • userId: This is your shop's parcelLab user-id and is used to map the start location.
  • courier: Here, the parcelLab courier code for the planned courier has to be specified.
  • location: This specifies the location of the recipient in one of two ways:
    1. Using the zip code and country, in the format <zip-code>_<country>, where <zip-code> is the pure-numerical zip code, and <country> the ISO 3166-1 alpha-3 code of the country. For example: 80331_DEU.
    2. The IP-Address of the visitor, e.g. 127.0.0.1.

Example

<head>
  ...
  <link href="https://cdn.parcellab.com/css/v2/parcelLab.min.css" rel="stylesheet">
  <link href="https://cdn.parcellab.com/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
  ...
  <script src="https://cdn.parcellab.com/js/v2/parcelLab.min.js" charset="utf-8"></script>
  <script type="text/javascript">
    var prediction = new ParcelLabPrediction('#deliveryTime', {
      // required
      userId: 122,
      courier: 'dhl-germany',
      location: '94261_DEU',

      // optional
      prefix: 'Lieferzeit:', // text to display left of the prediction
      suffix: 'Werktage', // text to display right of the prediction
      offset: 1, // offset in days to add to the predicted delivery time
      infoCaption: '#infoLabel', // where to display the info caption
      language: 'de', // language in which to display the info caption in
    });
    prediction.initialize(); // <~ this display the prediction in a dom-elem with id="#deliveryTime"
  </script>
</body>  

For developers

You will need GOOGLE_API_KEY for running the application locally. Andrej Fritz can provide it to you.

Develop

$ npm install
$ npm run start

Now, the test page is served on localhost:4000.

Build

$ npm run build

Minified index.js and index.css will be in the dist dir.

Deploy

Automatically deployed via GitHub Actions. The index.js and index.css files will be deployed as parcelLab.min.js and parcelLab.min.css on the CDN.

Installing through NPM

If you do not want to use our brebuilt and hosted version - you can also install it yourself thtough NPM.

$ npm i @parcellab/js-plugin

Afterwards you should be able to use it like this:

import { ParcelLab } from '@parcellab/js-plugin/bundle/module.min.js';
import '@parcellab/js-plugin/bundle/module.min.css';

const options = { rerouteButton: 'left', show_searchForm: 'true' };
const plPlugin = new ParcelLab('#pl-trace', options);

parcellab-js-plugin's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parcellab-js-plugin's Issues

Add custom class for tracking selection pills

If we do have multiple tracking numbers and select via ?u=1&orderNo=, can we add a custom class depending on the current status of the tracking?

So they could highlight the pills in red if there's an exception with their own CSS, for example.

Search form doesn't show results

Allerdings wollten wir jetzt das Suchformular integrieren, wenn die Seite im Shop ohne Sendungsnummer aufgerufen wird. Dazu habe ich wie in der Doku beschrieben die Initialisierung mit den entsprechenden Parametern aufgerufen:

parcelLab.initialize({ show_searchForm: true, userId: 1, });

Allerdings ist die Ausgabe auf der Seite die gleiche, wie bei einer Initialisierung ohne die entsprechenden Parameter.

Ich sehe im Code auch, dass eigentlich ein Fehler geworfen werden sollte, wenn man keine userId angibt:

console.error("โš ๏ธ You must pass your userId in the options if you want to display a searchForm!")

Das habe ich auch einmal probiert (keine userId angegeben) und keine Fehlermeldung in der Konsole sehen kรถnnen. รœbersehe ich da irgendetwas? Die Anzeige der Test-Tracking-Nummern, die du uns gegeben hast funktioniert soweit ohne Probleme.

General Components

General (small parts to be used by different components or that canโ€™t be grouped in another category):

Alert.js

Banner.js -> in case a banner_link or image is available

MoreButton.js

Loading.js

Tabs (folder?) -> TabsContainer.js & Tab.js

Icons (folder?) -> Icon.js & IconState.js

Note.js

Footer.js ??

Maps Component

Maps:

LivetrackingMap.js ** Check to use just one general Map component

PickUpMap.js ** Check to use just one general Map component

MapsFooter.js

Julians style suggestions ๐Ÿ’…

1

Maybe extend .pl-contact-btn with

    min-width: 260px;
    height: 28px;
    padding-top: 3px;

Screen Shot 2018-02-16 at 20.54.05.png

2

Could you create sample trackings for each status, based on dhl-germany / 00PL16120004

3

Remove #pl-tracking-heading completely? I think it's superfluous.

Also we can shorten the label for the details button (in the backend)

Weitere Informationen zu DHL

Or maybe even colorize it?
Screen Shot 2018-02-16 at 21.05.17.png

<span class="label" style="
    color: #D40511;
    background-color: #FFCD04;
    font-size: 12px;
    padding-bottom: 2px;
">DHL</span>

4

.pl-tab needs cursor: pointer;

Tracking Info Component

Tracking-info (right now tracking-delivery which is an irrelevant name):

Tracking-data:

Subheading.js

Header.js

LivetrackingLink.js

TrackingHeading.js

Prediction.js (this includes a Calendar and a TimeBox that can be moved into a component). This is to show the Estimated Delivery Date, may be โ€œPredictionโ€ is not the best name.

Checkpoint.js

NextAction.js (StatusDetails?)

Returned.js

Calendar.js ???

TimeBox.js ???

RerouteLink.js (and RerouteLinkShort.js, we could group it in one component)

FurtherInfos.js

Code snippet to inject custom text into split-order pills

Currently the selection for split-orders looks like this:

Screenshot 2019-04-12 at 11.28.58.png

Now we want customers to be able to modify these buttons individually using the onnRendered hook.

Can we provide a JS function to be inserted there that inject additional titles based on the carrier so that it looks like this?

Screenshot 2019-04-12 at 11.31.40.png

fix high security vulnerability of parcel package reported by npm

=== npm audit security report ===

# Run  npm install --save-dev [email protected]  to resolve 1 vulnerability
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ High          โ”‚ Missing Origin Validation                                    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Package       โ”‚ parcel-bundler                                               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Dependency of โ”‚ parcel-bundler [dev]                                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Path          โ”‚ parcel-bundler                                               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ More info     โ”‚ https://nodesecurity.io/advisories/721                       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

So as far as I understand this only allows a theoretical attacker to steal the uncompressed source and only if the developers machine is accessible from the internet. Shouldn't affect us, but since the fix should be extremely simple...

change tracking page message for orders that aren't in our system yet

Use-case: The recipient gets the order/dispatch confirmation confirmation straight from the shop including our link. However the order isn't in our system yet. Then he/she gets a default text saying "not in our system"Screenshot 2018-12-04 at 14.32.41.png

Can we change this content to a message saying "dispatch will take place soon" already including the icons etc . See: https://www.rosaoazul.es/shipment-tracking/?lang=es&u=1612174&orderNo=ES595949495

Tested with Firefox v24?

There might be issues with older version of Firefox

We should also include a no-javascript-notice in our HTML code

Couriers codes

Hi there,
is there any place where I can find full list of courier codes? Official ParcelLab documentation is useless in this topic, in this plugin code I've found only four german courier codes mapping.
Best regards.

Delivery Info Component

Delivery-info:

DeliveryAddress.js

PickUpLocation.js

OpenningHours.js

VoteCourier.js (may be this could be moved to Social?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.