1. 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?

Discussion in 'XenForo Questions and Support' started by System0, Apr 26, 2014.

  1. System0

    System0 Active Member

    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?
     
  2. Mike

    Mike XenForo Developer Staff Member

    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.
     
  3. AndyB

    AndyB Well-Known Member

  4. System0

    System0 Active Member

    Sorry, I should have clarified. The variables within the echo function are passed from PayPal, so PHP has to be used.
     
  5. Chris D

    Chris D XenForo Developer Staff Member

  6. System0

    System0 Active Member

    Yeah Andy's solution looks suitable. I will try that. Thanks :)
     
  7. AndyB

    AndyB Well-Known Member

    My pleasure happy to help.
     
    System0 likes this.
  8. System0

    System0 Active Member

    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 :)
     

Share This Page