Piano Analytics tracks marketing campaigns through tagging: you add at_ parameters to your campaign links, and the SDK turns them into src_ properties in your events. To take a campaign into account, you need to populate at least src_medium (Source and Campaign - Type) and src_campaign (Campaign - Name).
Tag campaign links
As explained in the developers' documentation, the SDK interprets any URL parameter prefixed with at_ as a campaign parameter, and transforms it into a src_ property in your events.
For example, with this URL:
https://www.site.com/?at_medium=MySource&at_campaign=MyCampaign&at_myproperty=MyValue&at_myotherproperty=MyOtherValue
You find these property and value pairs in your events:
|
URL parameter |
Property |
Value |
|---|---|---|
|
|
|
MySource |
|
|
|
MyCampaign |
|
|
|
MyValue |
|
|
|
MyOtherValue |
You need to declare custom parameters, here src_myproperty and src_myotherproperty, in your Data Model. The "src_" prefix is required.
Prefer using UTM parameters? The SDK can also use them for source attribution. Set the campaignPrefix configuration to include "utm_", for example pa.setConfiguration("campaignPrefix", ["at_", "utm_"]). If a link has both prefixes, the order in campaignPrefix decides which one wins. See Can we retrieve information from UTM campaigns?
Mobile applications
Mobile apps don't automatically read URL query strings the way a web page does. You need to populate the properties that start with src_ yourself in the tagging, as in this code example. If your acquisition uses deep links, deferred deep links or other mechanisms, your app must extract the campaign values and send them in the first events of the visit.
Learn more in our dedicated FAQ Can I measure traffic sources on mobile apps?
Overwrite the marketing source
The marketing source is defined on the first event of the visit, so in some situations you might need to overwrite it. To do so, send an event with src_force set to "true", along with src_campaign and src_medium. This applies in two cases:
-
Consent or hybrid measurement: if the first events of the visit are sent in exempt mode, before consent, the marketing source may not be stored. When the visitor later accepts your consent banner, send an event with
src_force,src_campaignandsrc_mediumto update the source of that visit.
Send src_force: true on an event triggered by the consent action, usually a click or a dedicated custom event. This avoids inflating page display metrics and skewing bounce rate analysis.
-
"Last campaign wins": to attribute a visit to the most recent campaign rather than the first one seen in the visit, use
src_force,src_campaignandsrc_mediumas part of your strategy.