Choosing the correct Javascript SDK is the first decision you'd need to make when implementing Analytics on your website. There are various ways to include the required JS in your website based upon how your website's templates and/or content management system is setup.
The first choice to make is which JS version to include:
Capability | Standard | Banner | CMP |
---|---|---|---|
Pageviews | |||
Events | |||
Actions | |||
Viewable impressions | |||
Aggregates | |||
Consent | Create your own | Consent banner
| IAB TCF 2.2 compatible consent wall
|
Javascript snippet | Standard snippet | Banner snippet | CMP snippet |
<script>
(function(w,d,c,u,n,a,s){w[n+'_queue']=w[n+'_queue']||[];w[n]=function(){w[n+'_queue'].push
(Array.prototype.slice.call(arguments))};var f=d.getElementsByTagName(c)[0];var j=d.createElement(c);
j.async=true;j.type='module';j.src=u+(u.indexOf('?')>=0?'&':'?')+'aid='+a+(n&&n!=='osb'?'&name='+n:'')+
(s?'&sid='+s:'');f.parentNode.insertBefore(j,f)})(window,document,'script',
'https://${TRACKER_URL}/js/osb.min.mjs','osb','${ACCOUNT_ID}','${DEFAULT_SITE_ID}');
// Tracking events go here...
</script>
Make sure to replace the following text with the values that apply to your website. Contact us for guidance.
${TRACKER_URL}
replace with your tracker URL${ACCOUNT_ID}
replace with your account ID${DEFAULT_SITE_ID}
replace with a default site IDThis is a special version of the analytics JS library that includes a cookie banner that can be customized.
<script>
(function(w,d,c,u,n,a,s){w[n+'_queue']=w[n + '_queue'] || [];w[n]=function(){w[n+'_queue'].push
(Array.prototype.slice.call(arguments))};var f=d.getElementsByTagName(c)[0];var j=d.createElement(c);
j.async=true;j.type='module';j.src=u+(u.indexOf('?')>=0?'&':'?')+'aid='+a+(n&&n!=='osb'?'&name='+n:'')+
(s?'&sid='+s:'');f.parentNode.insertBefore(j,f)})(window,document,'script',
'https://${TRACKER_URL}/js/osb-banner.min.mjs','osb','${ACCOUNT_ID}','${DEFAULT_SITE_ID}');
osb('consent', { consent banner options... }
// Tracking events go here...
</script>
${TRACKER_URL}
replace with your tracker URL${ACCOUNT_ID}
replace with your account ID${DEFAULT_SITE_ID}
replace with a default site IDThis is a special version of the analytics JS library that includes Onesecondbefore's Consent Management Platform (CMP).
It has exactly the same possibilities as the regular library, only osb('consent', ...);
now uses
Onesecondbefore's IAB TCF v2.0 compatible Consent Management Platform.
See the reference#consent-cmp for more details.
<script>
(function(w,d,c,u,n,a,s){w[n+'_queue']=w[n + '_queue'] || [];w[n]=function(){w[n+'_queue'].push
(Array.prototype.slice.call(arguments))};var f=d.getElementsByTagName(c)[0];var j=d.createElement(c);
j.async=true;j.type='module';j.src=u+(u.indexOf('?')>=0?'&':'?')+'aid='+a+(n&&n!=='osb'?'&name='+n:'')+
(s?'&sid='+s:'');f.parentNode.insertBefore(j,f)})(window,document,'script',
'https://${TRACKER_URL}/js/osb-cmp.min.mjs','osb','${ACCOUNT_ID}','${DEFAULT_SITE_ID}');
osb('consent', { consent CMP options... }
// Tracking events go here...
</script>
Make sure to replace the following text with the values that apply to your website. Contact us for guidance.
${TRACKER_URL}
replace with your tracker URL${ACCOUNT_ID}
replace with your account ID${DEFAULT_SITE_ID}
replace with a default site IDThe source code of the Android SDK is released as open source software under the Mozilla Public License.
Add the following repository and dependency to your app's build.gradle
file:
repositories {
...
maven {
url "https://www.onesecondbefore.com/repository"
}
}
dependencies {
...
implementation 'com.onesecondbefore.tracker:tracker-android:7.5.1'
}
After installation, consult our mobile reference documentation. Need help? Contact support.
Our IAB TCF Consent Wall can be integrated easily if you take the steps below. We map the purposes and special features as recommended by Google. Supported by SDK version 7.4+.
AndroidManifest.xml
(see below)More background info can be found at Google.
Add the default consent states in your app's AndroidManifest.xml
in the following way. More info can be found at Google.
<meta-data android:name="google_analytics_default_allow_analytics_storage" android:value="true" />
<meta-data android:name="google_analytics_default_allow_ad_storage" android:value="false" />
<meta-data android:name="google_analytics_default_allow_ad_user_data" android:value="false" />
<meta-data android:name="google_analytics_default_allow_ad_personalization_signals" android:value="false" />
Add the following code to integrate Google Consent Mode with the IAB TCF Consent Wall.
// Add callback function to OSB SDK. This function will be called directly after the user has set
// the consent in the CMP.
mOsb.addGoogleConsentCallback(consent -> {
Map consentMap = new HashMap<>();
consent.forEach((t,s) -> consentMap.put(FirebaseAnalytics.ConsentType.valueOf(t),
FirebaseAnalytics.ConsentStatus.valueOf(s)));
mFirebaseAnalytics.setConsent(consentMap);
});
Below is an example of how to retrieve the Google Consent Mode items.
// Directly request Google Consent Mode Payload from the OSB SDK. The SDK stores the given consent,
// if no consent has been given yet this function will return an empty map.
public void getGoogleConsentPayload() {
if (mOsb == null){
inializeOSB();
}
Map consentMap = new HashMap<>();
mOsb.getGoogleConsentPayload().forEach((t,s) -> consentMap.put(FirebaseAnalytics.ConsentType.valueOf(t),
FirebaseAnalytics.ConsentStatus.valueOf(s)));
Log.i(TAG, consentMap.toString());
}
The source code of the iOS SDK is released as open source software under the Mozilla Public License (MPL).
The OSB SDK can be integrated via CocoaPods.
target '[Your Target Name]' do
pod 'onesecondbefore-tracker'
end
Use import OSB
. We don't require any additional bridging header to use this pod file.
After installation, consult our mobile reference documentation. Need help? Contact support.
Our IAB TCF Consent Wall can be integrated easily if you take the steps below. We map the purposes and special features as recommended by Google. Supported by SDK version 7.4+.
info.plist
(see below)More background info can be found at Google.
Add the default consent states in your app's info.plist
in the following way. More info can be found at Google.
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE</key> <true/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE</key> <false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA</key> <false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS</key> <false/>
Add the following code to integrate Google Consent Mode with the IAB TCF Consent Wall.
// Create a callback function
func googleConsentCallback(consent: [String: String]) -> Void {
Analytics.setConsent(Dictionary(uniqueKeysWithValues: consent.map { t, s in (ConsentType(rawValue: t),
ConsentStatus(rawValue: s)) }))
}
// Pass callback function to OSB SDK
osb.config(accountId: accountId, url: trackerUrl, siteId: siteId, consentCallback: googleConsentCallback)
Add the following code to get the Google Consent Mode settings and log them.
// Directly request Google Consent Mode Payload from the OSB SDK. The SDK stores the given consent,
// if no consent has been given yet this function will return an empty dictonary.
func getGoogleConsentModePayload() {
if let googleConsent = osb.getGoogleConsentModePayload() {
let consent = Dictionary(uniqueKeysWithValues: googleConsent.map { t, s in (ConsentType(rawValue: t),
ConsentStatus(rawValue: s)) })
print(consent)
}
}