• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.3 How to Insert PHP tracking Code Into Xenforo Template?

System0

Active member
#1
I want to place a tracking pixel in a specific Xenforo template. The pixel is in the form:

PHP:
<?php

echo ("<img src=\"https://blahblahblah.com/?variable1=12345&variable2=54321&variable3=98765\" width=\"1\" height=\"1\">");

?>
From what I have read, I need to do this using an XenForo callback. I have read some documentation on this but I am unsure about it all.

Is it just a matter of creating a php file with the above code and then calling it from the template? Does the file have to be placed in a specific folder?
 

Mike

XenForo developer
Staff member
#2
Based on what you're showing, the <img> tag itself is just plain HTML -- no PHP involved -- so you can simply insert that into the template you want.
 

System0

Active member
#4
Based on what you're showing, the <img> tag itself is just plain HTML -- no PHP involved -- so you can simply insert that into the template you want.
Sorry, I should have clarified. The variables within the echo function are passed from PayPal, so PHP has to be used.
 

System0

Active member
#8
I appreciate the help given in this thread so far. Unfortunately, I have not been able to integrate the code correctly.

To give you more information, I am trying to integrate an affiliate tracking pixel from ShareASale.

To do this, I created an index.php file and saved it at library/shareasale/index.php. This is the code for that file:

Code:
<?php

class shareasale_index {

  public static function getHtml() {
  $output = '<img src=\"https://shareasale.com/sale.cfm?amount=$amount&tracking=$tx_token&transtype=SALE&merchantID=12345\" width=\"1\" height=\"1\">';
  return $output;
  }
}
I then added the following code to the account_upgrade_purchase template file:

Code:
<xen:callback class="shareasale_index" method="getHtml"></xen:callback>
This does add the code correctly to the page, however upon testing I realised that it did not pass the variables correctly.

When someone has upgraded their membership, PayPal's Auto Return feature takes them back to XenForo to confirm the upgrade as went through correctly. To be more specific, XenForo says "Thank you for purchasing this upgrade.When the payment has been approved, your account will be upgraded."

Unfortunately, the variables are not being passed to the function correctly using the file I created. The confirmation page adds this to the source:

Code:
<img width='\"1\"' height='\"1\"' src='\"https://shareasale.com/sale.cfm?amount=$amount&amp;tracking=$tx_token&amp;transtype=SALE&amp;merchantID=12345\"'>
But it should add something like this (example shows a transaction of $1):

Code:
<img src="https://shareasale.com/sale.cfm?amount=1.00&tracking=DNHQ2&transtype=sale&merchantID=12345" with="1" height="1" alt=""/>
My PHP skills are very poor (to say the least), so I am hoping this is an easy fix. Could someone check the code above and see where I have gone wrong :)