Title: Adding a tracking script
Last modified: October 16, 2020

---

# Adding a tracking script

 *  Resolved [keithasmith](https://wordpress.org/support/users/keithasmith/)
 * (@keithasmith)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/)
 * How do you get a tracking script for a third party into the header on these? 
   I’ve tried several things and nothing has worked so far. I normally can set a
   global one via a tracking manager plugin. And it will show on all posts and pages.
   I’m assuming since this is a special post type it is scripting all of that out?
 * It’s worked great so far except that.
 * Help is needed, thanks.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fadding-a-tracking-script-2%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 14 replies - 1 through 14 (of 14 total)

 *  Plugin Author [Pascal Birchler](https://wordpress.org/support/users/swissspidy/)
 * (@swissspidy)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13544956)
 * Hi there,
 * Which tracking scripts and tracking manager plugins are you typically using?
 * Since Web Stories rely on the underlying AMP format, printing of tracking scripts
   works a bit differently from regular pages as they need to be valid AMP.
 * For example, to print a Facebook pixel you’d need to use `<amp-pixel src="https://
   www.facebook.com/tr?id=<ID>ev=PageView&noscript=1" layout="nodisplay"></amp-pixel
   >` at the right place, before the closing `</amp-story>` tag.
 * You can do so by hooking into the `web_stories_print_analytics` action.
 * A simple example would look like this:
 *     ```
       add_action(
         'web_stories_print_analytics',
         function() {
           echo '<amp-pixel src="https://www.facebook.com/tr?id=<ID>ev=PageView&noscript=1" layout="nodisplay"></amp-pixel>';
         }
       );
       ```
   
    -  This reply was modified 5 years, 7 months ago by [Pascal Birchler](https://wordpress.org/support/users/swissspidy/).
      Reason: fixed code formatting
 *  Thread Starter [keithasmith](https://wordpress.org/support/users/keithasmith/)
 * (@keithasmith)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13544975)
 * So this is the script for our Ad company –
    `<script async src='https://tag.simpli.
   fi/sifitag/9a3b1250-6036-0136-ee82-06659b33d47c'></script>` I’m trying to use
   these as landing pages for the ads. Since a lot of this traffic is mobile this
   presents a very nice format – I think for mobile.
 * So I normally use Tracking Script Manager from [https://wordpress.org/plugins/tracking-script-manager/](https://wordpress.org/plugins/tracking-script-manager/)
 * I’ve tried with Google Tag Manager as well but it shows everywhere but the Web
   Stories. However, I’m not very familiar with it yet, so I could be doing something
   wrong there.
    -  This reply was modified 5 years, 7 months ago by [keithasmith](https://wordpress.org/support/users/keithasmith/).
 *  Thread Starter [keithasmith](https://wordpress.org/support/users/keithasmith/)
 * (@keithasmith)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13544995)
 * So would you add your example to the Tracking.php or Analytics.php file? Or somewhere
   else?
 * Thanks for your help.
    -  This reply was modified 5 years, 7 months ago by [keithasmith](https://wordpress.org/support/users/keithasmith/).
 *  Plugin Author [Pascal Birchler](https://wordpress.org/support/users/swissspidy/)
 * (@swissspidy)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13545047)
 * Neither!
 * That example would belong into your theme’s `functions.php` file or a dedicated
   custom plugin. You should **not** modify the Web Stories plugin files as these
   changes get overridden with any update.
 * Example:
 *     ```
       add_action(
         ‘web_stories_print_analytics’,
         function() {
           echo ‘<amp-pixel src="https://tag.simpli.fi/sifitag/9a3b1250-6036-0136-ee82-06659b33d47c" layout="nodisplay"></amp-pixel>’;
         }
       );
       ```
   
 * Note: we’ll be looking into how we can best support plugins like Tracking Script
   Manager so you don’t have to deal with this manually.
 *  Thread Starter [keithasmith](https://wordpress.org/support/users/keithasmith/)
 * (@keithasmith)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13545049)
 * Ah ok, thanks! I did try that earlier but it was without the web-storeies_print_anlytics
   action. Trying that out now. Everyone really liked how these stories turned out
   btw.
 * You all are doing some nice work with this.
 * Is there a way to support mailto links and tel links?
    -  This reply was modified 5 years, 7 months ago by [keithasmith](https://wordpress.org/support/users/keithasmith/).
 *  Thread Starter [keithasmith](https://wordpress.org/support/users/keithasmith/)
 * (@keithasmith)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13545086)
 * Ok, the echo line is getting this error – syntax error, unexpected ‘src’ (T_STRING),
   expecting ‘;’ or ‘,’
 *  Thread Starter [keithasmith](https://wordpress.org/support/users/keithasmith/)
 * (@keithasmith)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13545098)
 * Ok figured it out, I think. it needed the straight quote marks. Now to check 
   it!
 *  Thread Starter [keithasmith](https://wordpress.org/support/users/keithasmith/)
 * (@keithasmith)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13545113)
 * Well, it’s working for everything else but those pages looks like. 🙁
 *  Thread Starter [keithasmith](https://wordpress.org/support/users/keithasmith/)
 * (@keithasmith)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13553746)
 *     ```
       add_action(
         'web_stories_print_analytics',
         function() {
           echo '<amp-pixel src="https://tag.simpli.fi/sifitag/9a3b1250-6036-0136-ee82-06659b33d47c" layout="nodisplay"></amp-pixel>';
         }
       );
       add_action('wp-footer', 'web_stories_print_analytics');
       ```
   
 * Ok, I got this to work using this. It is showing up. But I think I need it in
   the header.
 *  [Luckyna San](https://wordpress.org/support/users/luckynasan/)
 * (@luckynasan)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13558223)
 * [@keithasmith](https://wordpress.org/support/users/keithasmith/) Hi there! Glad
   it is working for you. Please let us know if there is anything further we can
   help with on this issue. Thanks.
 *  Thread Starter [keithasmith](https://wordpress.org/support/users/keithasmith/)
 * (@keithasmith)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13563505)
 * Ok, ran into a slight issue. The tag won’t fire with double quotes (” tag “) 
   when I try single quotes php doesn’t like it. Is there a way around this? The
   tag needs to display like this:
 * `<script async src='https://tag.simpli.fi/sifitag/9a3b1250-6036-0136-ee82-06659b33d47c'
   ></script>`
 * I get this error when I try – Your PHP code changes were rolled back due to an
   error on line 113 of file wp-content/themes/ewc-2012/functions.php. Please fix
   and try saving again.
 * syntax error, unexpected ‘https’ (T_STRING), expecting ‘;’ or ‘,’
 *  [Luckyna San](https://wordpress.org/support/users/luckynasan/)
 * (@luckynasan)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13568692)
 * [@keithasmith](https://wordpress.org/support/users/keithasmith/) Thanks for the
   update. We will investigate further and provide you with any updates.
 *  Plugin Author [Pascal Birchler](https://wordpress.org/support/users/swissspidy/)
 * (@swissspidy)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13583497)
 * [@keithasmith](https://wordpress.org/support/users/keithasmith/) Quotes should
   really not make a difference. Note that you cannot use `<script>` for Web Stories
   pages as it will cause your story to become invalid AMP.
 * The code I shared with you is correct (after fixing the quotes) and it is correct
   to be in the footer.
 *  [Luckyna San](https://wordpress.org/support/users/luckynasan/)
 * (@luckynasan)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13617103)
 * [@keithasmith](https://wordpress.org/support/users/keithasmith/) We are going
   to mark your topic as resolved as we haven’t received a response. Please feel
   free to open a [new support topic](https://wordpress.org/support/plugin/web-stories/#new-post)
   if you continue to experience any issues. Thank you!

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘Adding a tracking script’ is closed to new replies.

 * ![](https://ps.w.org/web-stories/assets/icon.svg?rev=2386543)
 * [Web Stories](https://wordpress.org/plugins/web-stories/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/web-stories/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/web-stories/)
 * [Active Topics](https://wordpress.org/support/plugin/web-stories/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/web-stories/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/web-stories/reviews/)

 * 14 replies
 * 3 participants
 * Last reply from: [Luckyna San](https://wordpress.org/support/users/luckynasan/)
 * Last activity: [5 years, 6 months ago](https://wordpress.org/support/topic/adding-a-tracking-script-2/#post-13617103)
 * Status: resolved