- 23 Feb 2023
- 5 Minutes to read
- Print
- DarkLight
Tracking Codes
- Updated on 23 Feb 2023
- 5 Minutes to read
- Print
- DarkLight
Overview
If you're running a marketing campaign, it's important to track its effectiveness to gain insights and improve your conversion. One popular tool for tracking website conversions is Facebook Pixel.
To get started, you'll need to set up tracking codes for Facebook.
In this article, we'll guide you through the basics of adding tracking codes to your e-commerce forms.
Should I use the Custom JS or the Pixel section?
If you see a <script>
tag, you will need to add the code to the Custom JS section of the configuration screen.
Pixels were originally the standard tracking method for website analytics and ad campaigns, so tracking codes are still commonly referred to as "pixels." However, modern tracking codes are often provided as JavaScript scripts that perform a wider range of tasks, but still serve the same tracking and analysis purposes as traditional pixels. So, don't be confused if you encounter a tracking code that is called a "pixel" but is actually a JavaScript script.
In order to determine whether a tracking code is provided as a JavaScript script, you can look at the code itself.
If the tracking code is provided as a JavaScript script, you'll typically see a block of code that is enclosed within <script>
tags in the website's HTML. The code may contain a tracking ID or other tracking parameters that are used to identify the website and the user's behavior on the site.
On the other hand, if the tracking code is provided as a traditional pixel, it will typically be embedded in the website as an image file with a
.png
,.gif
, or .jpg
extension. The pixel will often be a 1x1 transparent image that is not visible to the user, but sends tracking data to the tracking server when the user loads the web page.
In some cases, tracking codes may use a combination of pixels and JavaScript to track user behavior. In these cases, you may see both <script>
tags and image files with tracking parameters embedded in the website's HTML.
Variables
By including variables in your tracking pixels, you can dynamically pass information back to your analytics tools.
Our widget will use the values that were used during the transaction.
For example, it could send back what was the coupon code that was used, alongside the first and last name of the user that made the purchase.
Below is a list of possible variables and description of the value that would be generated and passed back.
Stripe
Key | Value | Description |
---|---|---|
sf.location | 8787767 | Location ID where user was created |
sf.product.name | Millennium Falcon Training | Name of the product |
sf.product.price_in_cents | 29700 | Price of the product in cents |
sf.product.setupFee_in_cents | 9900 | Price of the setup fee in cents |
sf.product.priceId | price_987654321 | The Stripe product’s price ID |
sf.user.fname | Luke | The first name that the user entered |
sf.user.lname | Skywalker | The last name that the user entered |
sf.user.email | luke.skywalker@rebel.com | The email that the user entered |
sf.user.phone2 | 555-123-4567 | The phone number that the user entered |
sf.user.login | lukeskywalker | The username that the user entered |
sf.coupon | JEDI20OFF | The coupon code used at checkout |
sf.campaignId | rebellion | The campaign ID set in the widget settings |
Maxio (Chargify)
Key | Value | Description |
---|---|---|
{subscriptionId} | 1138456 | ID of subscription |
{productName} | Holocron Archive Reading 101 | Name of the subscribed product |
{productHandle} | holocron-archive-101 | Handle of the subscribed product |
{productId} | 987654321 | ID of the subscribed product |
{productPrice} | 59.99 | Price of the subscribed product |
{transactionId} | 87654321 | ID of the transaction |
{tax} | $5.00 | Amount of tax charged |
{totalAmount} | 64.99 | Total amount charged |
{adjustedAmount} | 59.99 | Product price - Coupon discount |
{title} | Jedi Council Annual Membership | Title of the subscription (From settings page title) |
{subscriptionType} | Individual Purchase | Type of subscription |
{system} | 1138 | LSVT System ID |
{coupon} | JEDIKNIGHT | The coupon code used at checkout |
{currency} | Republic Credit | Currency used for the subscription payments |
Authorize.net
Key | Value | Description |
---|---|---|
anetf.location | 8787767 | Location ID where user was created |
anetf.product.name | Lightsaber Training Plan | Name of the product |
anetf.product.price_in_cents | 19999 | Price of the product in cents |
anetf.product.setupFee_in_cents | 4999 | Price of the setup fee in cents |
anetf.product.priceId | 8edc1920-a4e7-427a-952c-90a4fb240474 | The product’s price ID |
anetf.user.fname | Leia | The first name that the user entered |
anetf.user.lname | Organa | The last name that the user entered |
anetf.user.email | princessleia@alderaan.gov | The email that the user entered |
anetf.user.phone2 | 555-123-4567 | The phone number that the user entered |
anetf.user.login | leiaorgana | The username that the user entered |
anetf.coupon | FORCE10 | The coupon code used at checkout |
A typical Facebook "Pixel" code is a Javascript code provided in multiple parts that may look similar to examples below.
Example Code Part 1:
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID_HERE');
fbq('track', 'PageView');
</script>
<noscript>
<img height="1" width="1" src="https://www.facebook.com/tr?id=YOUR_PIXEL_ID_HERE&ev=PageView&noscript=1"/>
</noscript>
<!-- End Facebook Pixel Code -->
The <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=159417911277514&ev=PageView&noscript=1"/></noscript>
tag serves the purpose of providing an alternative tracking mechanism for clients with disabled JavaScript.
However, including this tag in the script section is unnecessary since it instructs the browser to read from a pixel image if JavaScript is disabled. Since JavaScript needs to be enabled for our checkout to function properly, this part of the code should be omitted.
Example Code Part 2:
<script>
fbq('track', 'Purchase', {
value: 25.00,
currency: 'USD',
});
</script>
The example code part 1 would be inserted into the main HTML code of the checkout page or the page holding the widget.
The example code part 2 would need to be inserted into the Custom JS section of the configuration screen and in the appropriate step.
For example, if you want to track the "Purchase" event, you would insert the code in the Step 3 - Username Form Code of the checkout flow.
In addition, you would use the dynamic variables that are proper to your needs and could be looking like:
fbq(‘track’, ‘Purchase’, {
value: sf.product.priceincents,
coupon: sf.coupon,
currency: 'USD',
contents: [{
id: sf.product.priceId
},
quantity: 1
}],
content_type: 'product'
});
If using Stripe Widget, do NOT include the <script>
and </script>
tags in your tracking codes.
If using Maxio (Chargify), use the tags.
For questions or assistance, please contact us at support@lightspeedvt.com