# 如何放置流量分析代码？

**URL:** https://meta.discourse.org/t/how-to-put-traffic-analytics-code/88320
**Category:** Support
**Created:** [2018年五月24日 00:24 UTC](https://meta.discourse.org/t/how-to-put-traffic-analytics-code/88320 "2018-05-24T00:24:59Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![Cameron\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cameron_d/32/97535_2.png) [@Cameron\_D](https://meta.discourse.org/u/Cameron_D)
#### Post date: [2018年五月24日 00:53 UTC](https://meta.discourse.org/t/how-to-put-traffic-analytics-code/88320/5 "2018-05-24T00:53:15Z")

</div>

However, with some modifications to the statcounter script you should be able to get it to run on each page load, this would probably be your starting point:

> [@How do you force a script to refire on every page load in Discourse?](https://meta.discourse.org/t/how-do-you-force-a-script-to-refire-on-every-page-load-in-discourse/74856/5):
>
> I think you can use the PluginAPI onPageChange function to do what you are looking for. See: [Using the JS API](https://meta.discourse.org/t/using-the-pluginapi-in-site-customizations/41281) Here’s an example function: \<script type="text/discourse-plugin" version="0.8"\> api.onPageChange(() =\>{ randBackground(); }); function randBackground() { $('body').css('background-color', '#'+(Math.random()\*0xFFFFFF\<\<0).toString(16)); } \</script\> Update: If you are looking to apply similar changes to post bodies, see [post #26 below](https://meta.discourse.org/t/how-do-you-force-a-script-to-refire-on-every-page-load-in-discourse/74856/26).

---

_[View the full topic](https://meta.discourse.org/t/how-to-put-traffic-analytics-code/88320)._
