<p>Since it sounds like you're rolling-your-own, and can afford a relatively simple implementation, I'd recommend checking out the <a href="https://docs.craftcms.com/v3/dev/functions.html#seq-name-length-next" rel="nofollow noreferrer"><code>seq(…)</code> Twig function</a> that Craft provides.</p>

<pre><code>{% do seq("ad-impressions-#{ad.uid}") %}
</code></pre>

<p>Then, if you have a dashboard of some kind for advertisers/partners, you could display those tallies by iterating over their “owned” advertisements:</p>

<pre><code>{% for ad in ads %}
    {{ ad.title }} views: {{ seq("ad-impressions-#{ad.uid}", null, false) }}
{% endfor %}
</code></pre>

<p>Here, the third argument tells the function to <em>read</em> the value, but not increment it.</p>

<blockquote>
  <p>Of course, this is <em>extremely</em> crude. It assumes you only need to count <em>the number of times an ad is rendered into a page</em>, and makes no guarantees about how many times it’s actually <em>seen</em>. It also won't increment if the page is cached.</p>
</blockquote>

<p>Overall, I'd recommend outputting the ad with some kind of identifying information, and firing a custom Google Analytics event… or—time permitting—write a custom controller to ping via AJAX when an ad is actually displayed in a browser. Keep in mind that somewhere in here, you're apt to be able to deliver a better product with an existing plugin! </p>

CC BY-SA 4.0
2018-12-30T18:27:07.480Z
Thank you. This is just the kind of information I was looking for.
Mosswalker
CC BY-SA 4.0
2018-12-30T01:20:11.777Z
2018-12-30T01:44:27.197Z
2018-12-30T01:44:27.197Z
August Miller
<p>We're adding advertising to our Craft site. The ads come from our business members and are displayed randomly with article pages, based on tags and categories. All that is working fine.</p>

<p>The question comes up, how to report impression counts of the ads back to the advertisers? I'm newish to Craft; I don't know if it is possible to write back to a field of an asset (displayCount = displayCount + 1 kind of thing).</p>

<p>Any ideas or suggestions would be appreciated.</p>

CC BY-SA 4.0
2018-12-28T20:32:45.557Z
Have you considered using a plugin like [Ad Wizard](https://www.doublesecretagency.com/plugins/ad-wizard)? (Disclaimer: I am the author)
Lindsey D
CC BY-SA 4.0
2018-12-29T02:40:26.927Z
No, have not. But I will. Thanks.
Mosswalker
<count>
How to count ad impressions
# How to count ad impressions

(Asked by: username_0 on 2018-12-28)

We're adding advertising to our Craft site. The ads come from our business members and are displayed randomly with article pages, based on tags and categories. All that is working fine.

The question comes up, how to report impression counts of the ads back to the advertisers? I'm newish to Craft; I don't know if it is possible to write back to a field of an asset (displayCount = displayCount + 1 kind of thing).

Any ideas or suggestions would be appreciated.

**Tags:** count
> **Comments:**
> **username_1**: Have you considered using a plugin like [Ad Wizard](https://www.doublesecretagency.com/plugins/ad-wizard)? (Disclaimer: I am the author)  
> **username_0**: No, have not. But I will. Thanks.  

---

## 1 answers

### Answer by username_2 on 2018-12-30. Score: 2 | Accepted answer

Since it sounds like you're rolling-your-own, and can afford a relatively simple implementation, I'd recommend checking out the seq(…) Twig function that Craft provides.
{% do seq("ad-impressions-#{ad.uid}") %}

Then, if you have a dashboard of some kind for advertisers/partners, you could display those tallies by iterating over their “owned” advertisements:
{% for ad in ads %}
    {{ ad.title }} views: {{ seq("ad-impressions-#{ad.uid}", null, false) }}
{% endfor %}

Here, the third argument tells the function to read the value, but not increment it.

Of course, this is extremely crude. It assumes you only need to count the number of times an ad is rendered into a page, and makes no guarantees about how many times it’s actually seen. It also won't increment if the page is cached.

Overall, I'd recommend outputting the ad with some kind of identifying information, and firing a custom Google Analytics event… or—time permitting—write a custom controller to ping via AJAX when an ad is actually displayed in a browser. Keep in mind that somewhere in here, you're apt to be able to deliver a better product with an existing plugin!

> **Comments:**
> **username_0**: Thank you. This is just the kind of information I was looking for.  

---

