Tracking Codes
  • 23 Feb 2023
  • 5 Minutes to read
  • Dark
    Light

Tracking Codes

  • Dark
    Light

Article Summary

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?

TL;DR - In Summary:

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

KeyValueDescription
sf.location8787767Location ID where user was created
sf.product.nameMillennium Falcon TrainingName of the product
sf.product.price_in_cents29700Price of the product in cents
sf.product.setupFee_in_cents9900Price of the setup fee in cents
sf.product.priceIdprice_987654321The Stripe product’s price ID
sf.user.fnameLukeThe first name that the user entered
sf.user.lnameSkywalkerThe last name that the user entered
sf.user.emailluke.skywalker@rebel.comThe email that the user entered
sf.user.phone2555-123-4567The phone number that the user entered
sf.user.loginlukeskywalkerThe username that the user entered
sf.couponJEDI20OFFThe coupon code used at checkout
sf.campaignIdrebellionThe campaign ID set in the widget settings

Maxio (Chargify)

KeyValueDescription
{subscriptionId}1138456ID of subscription
{productName}Holocron Archive Reading 101Name of the subscribed product
{productHandle}holocron-archive-101Handle of the subscribed product
{productId}987654321ID of the subscribed product
{productPrice}59.99Price of the subscribed product
{transactionId}87654321ID of the transaction
{tax}$5.00Amount of tax charged
{totalAmount}64.99Total amount charged
{adjustedAmount}59.99Product price - Coupon discount
{title}Jedi Council Annual MembershipTitle of the subscription (From settings page title)
{subscriptionType}Individual PurchaseType of subscription
{system}1138LSVT System ID
{coupon}JEDIKNIGHTThe coupon code used at checkout
{currency}Republic CreditCurrency used for the subscription payments

Authorize.net

KeyValueDescription
anetf.location8787767Location ID where user was created
anetf.product.nameLightsaber Training PlanName of the product
anetf.product.price_in_cents19999Price of the product in cents
anetf.product.setupFee_in_cents4999Price of the setup fee in cents
anetf.product.priceId8edc1920-a4e7-427a-952c-90a4fb240474The product’s price ID
anetf.user.fnameLeiaThe first name that the user entered
anetf.user.lnameOrganaThe last name that the user entered
anetf.user.emailprincessleia@alderaan.govThe email that the user entered
anetf.user.phone2555-123-4567The phone number that the user entered
anetf.user.loginleiaorganaThe username that the user entered
anetf.couponFORCE10The coupon code used at checkout

Facebook

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 -->
NOTE

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.
Step 3 Code

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'
});
WARNING

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


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.