Integrate Shopping Analytics SDK
Last updated: Feb 27th, 2:37pm
Important: The PayPal Shopping Analytics SDK is available to select partners and merchants for approved use cases.
Set up your development environment
Before you can integrate the PayPal Shopping product suite, you must set up your development environment. After you get a token that lets you access protected REST API resources, you create sandbox accounts to test your web and mobile apps. For details, see Get started.
Then, return to this page to integrate the PayPal Shopping product suite.
Note: You must be in a live environment to obtain a production client-id
Install and instantiate
Install script
Set up your website to send the customer's shopping events to PayPal. Install and instantiate the SDK by adding the following code to the HEAD section of every page where you want to use it.
- Merchants
- Partners
1<script>2 ; (function (a, t, o, m, i, k) { a[m] = a[m] || [];3 a[m].push({ t: new Date().getTime(), event:4 'snippetRun' }); var f =5 t.getElementsByTagName(o)[0], e =6 t.createElement(o); e.async = !0; e.src =7 'https://www.paypal.com/sdk/js?components=shopping&client-id=' + i + '&merchant-id=' + k; f.parentNode.insertBefore(e, f);8 })(window, document, 'script', 'shoppingDDL', '<insert_partner_client_ID>', '<insert_merchant_ID>');9</script>
| Variable | Description |
|---|---|
client-id | For merchants, this is the production client id. For partners, this is the partner client id. |
merchant-id | For partners only. |
Initialize script
After loading the script into the pages, initialize the script. Depending on how your application manages JavaScript scopes, you may want to initialize the tracker object as shown in this example:
1<script>2 const pptag = {send: function (event, payload) {shoppingDDL.push({event, payload}); }, set: function (set) {shoppingDDL.push({set}); } };3</script>
We will use the pptag var defined above in the following examples.
Track shopper activity on your site
After you install and instantiate the SDK on your pages, you can track shoppers. The PayPal Shopping Analytics SDK uses shopping events to identify shoppers and understand their behavior on your site.
PayPal Analytics is JavaScript code that tracks visitor activity on your website. Use the following JavaScript functions from the PayPal Shopping Analytics SDK to implement and track activity.
Set data about the user
Before you start sending events, add attributes about the user that will be sent automatically on each event.
All events emitted on the page are attributed to this user.
Note: By default, the Tracker tracks events against an anonymous user and assigns them an auto-generated ID. If you later set user details, the Tracker includes those previously-anonymous events for that user
1// Example of an event emitted when a known user visits your website.2pptag.set({3 user_id: "3837394700",4 first_time_visit: false5})
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
user_id | string | no | The ID of the shopper in your system. You can use the shopper's email if you don't maintain user IDs. If not provided in the session, SDK will generate a random ID to track user activities for the session |
first_time_visit | boolean | no | Is this the user's first visit to your site? |
Track page view
Track page view
Use the page_view keyword to register user page views. The page the user visits can be a variety of types including HOME, CATEGORY, etc.
1// Registering a view on a category page2pptag.send("page_view", {3 page_type: "CATEGORY",4 page_path: "category/shoes",5 page_category_id: "b1b302f9-1ef9-4cae-b0fd-5735131c80f3",6 page_category_name: "Shoes"7})89// Registering a view on the home page10pptag.send("page_view", { type: "HOME" })
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
page_type |
string | yes | HOME, CATEGORY, SEARCH_RESULTS, DEALS, PRODUCT_CART, CHECKOUT, ORDER_CONFIRMATION |
page_name |
string | no | Name of the page. |
page_path |
string | no | Uniquely identify the page. |
page_category_name |
string | no | Name of the category that was viewed. |
page_category_id |
string | no | ID of the category that was viewed. |
deal_id |
string | no | ID of the deal that was viewed. |
deal_name |
string | no | Name of the deal that was viewed. |
deal_value |
string | no | Value of the deal that was viewed. |
search_results_count |
string | no | Number of results retrieved for given search query if page_type is SEARCH_RESULTS. |
cart_products |
CartProduct] | no | Products in the cart if page_type is PRODUCT_CART. The parameters of each item are equivalent to the product_view parameters below. |
Track a product view
Use the product_view keyword to register a page view event on a particular product. Supply details of the product in the payload.
1paypalAnalytics.send("product_view", {2 product_id: "188437",3 product_name: "Runner shoes model 2000",4 product_url: "https://test-site.com/socks",5 product_price: "200.00",6 product_brand: "Rabok",7 product_category_name: "Socks",8 product_category_id: "S1",9 product_discount: "4.50"10})
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
product_id |
string | yes | Product ID/SKU. |
product_name |
string | no | Product name. |
product_url |
string | no | Product page URL. |
product_price |
string | no | Product price. Example "200.00". |
product_brand |
string | no | Product brand. |
product_category_name |
string | no | Name of the category the product belongs to. |
product_category_id |
string | no | ID of the category the product belongs to. |
product_discount |
string | no | Discount amount. Example "4.50". |