AfterShip Pixel is a powerful tool for marketing campaign optimization and analytics with a strong commitment to data science. The AfterShip Pixel Web SDK and API make it simple to integrate.
Begin using AfterShip Pixel APIs with a few simple steps. Log in, get your API credentials, and start developing.
Currently, Pixel ID is available only to whitelisted users. Contact us to obtain one.
AfterShip provides two common integration methods in web development. Depending on how your store is deployed, you can choose one of them to quickly integrate AfterShip Pixel into your store.
$ npm install @aftership/web-pixels --save
or
$ yarn add @aftership/web-pixels
Currently, AfterShip Pixel ID is only available to whitelisted users. Please contact us to obtain the AfterShip Pixel snippet
If you installed using Add the AfterShip Pixel snippet, you can skip this step as the snippet already calls the initialization API.
Before reporting the first event, we need to call ASPixel.init
to complete the SDK initialization, allowing AfterShip Pixel to know the source of upcoming events.
If this step isn't correctly executed, subsequent events reported via Track won't reach the server.
ASPixel.init({
pixelId:"<AfterShipPixelId>"
})
The ASPixel.events contains a variety of semantic event methods that you can choose to bury events in the right scenarios. Each event method has an explicit typescript type.
SDK will send the request after calling ASPixel.events. Before calling this API, please make sure that your website is compliant with privacy regulations (e.g. GDPR, CCPA, etc.)
// Track search terms
ASPixel.events.clicked({
linkUrl: "test.com",
label: "test",
});
// Track a simpler version.
ASPixel.events.pageViewed();
After initializing ASPixel, you can call ASPixel.identify() to identify individual users. This method accepts customerId, and all subsequent event reports will include this customerId.
// Track search terms
// Add a customer ID
ASPixel.identify({
customerId: 'test customerId',
});
After identifying the user, it is also possible to resetIdentity the user by calling ASPixel.resetIdentiy(). After calling this,all events will not carry the user id.
// Track a simpler version.
// Add a user ID
ASPixel.track('$page_viewed', {
customer_id: "e4b0f8a6c9d64a2b8e2f0c67a8d4f9e2"
});
Enabling this won't report events but will print logs in the console.
Method: Call window.ASPixel.debug(true)
in the console.
Method: Call window.ASPixel.debug(false)
in the console.
- init
- Description: To initialize the SDK, you need to provide a pixelId to identify the store. This process is asynchronous, so be sure to handle it accordingly.
- Parameter:
await ASPixel.init({
pixelId:"<AfterShipPixelId>"
})
- events
- Description: For the event reporting method, provide the event name along with the corresponding parameters to report the event.
- Parameter:
ASPixel.events.pageViewed()
- debug
- Description: To debug data reporting, you can call the debug method under the window.ASPixel in the console to enable the debugging environment. Once enabled, events will not call the API; they will only output the event calls in the console.
- Parameter:
// fisrt time is open
window.ASPixel.debug()
// second time is close
window.ASPixel.debug()