-
Notifications
You must be signed in to change notification settings - Fork 229
Description
Is your feature request related to a problem? Please describe.
When loading the tracker as a Tag, using the Tag snippet, it is not currently possible (in v3.0.0-alpha.3) to load a plugin dynamically, you can only use the plugins already bundled into the tracker.
This can also be extended to the @snowplow/browser-tracker library so plugins can be added post creating a tracker.
Describe the solution you'd like
Following initialising a tracker:
window.snowplow('newTracker', 'sp1', '{collector_url}}, {
appId: 'simple-test-1',
eventMethod: 'post'
});
You can then dynamically load an external script plugin:
window.snowplow('addPlugin', ['snowplowPerformanceTiming', 'PerformanceTimingPlugin'], 'https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-performance-timing@3.0.0-alpha.3/dist/index.umd.min.js');
window.snowplow('addPlugin:sp1', ['snowplowAdTracking', 'AdTrackingPlugin'], 'https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-ad-tracking@3.0.0-alpha.3/dist/index.umd.min.js');
Or you can inject a Plugin object in:
window.snowplow('addPlugin:sp1', 'SimpleContextPlugin', {
SimpleContextPlugin: function() {
return {
contexts: function() {
return [
{
schema: 'iglu:com.acme/my_custom_context/jsonschema/1-0-0',
data: {
id: '1234'
},
},
];
}
}
}
});
When using the form:
window.snowplow('addPlugin', ['snowplowPerformanceTiming', 'PerformanceTimingPlugin'], 'https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-performance-timing@3.0.0-alpha.3/dist/index.umd.min.js');
there should be a final parameter, which controls whether tracking should be paused until the external script has loaded. Once the script is loading, tracking can resume. This is true by default and will pause tracking. Set this to false if you are ok with a context not being on events until the plugin loads. Beware of calling API methods (e.g. trackAdImpression from the Ad Tracking plugin) before the script has loaded if you set this final parameter to false.
window.snowplow('addPlugin', ['snowplowPerformanceTiming', 'PerformanceTimingPlugin'], 'https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-performance-timing@3.0.0-alpha.3/dist/index.umd.min.js', true);
The tracker will only be paused for a timeout period of 5000 milliseconds or until the script loads, whichever happens first.
When using @snowplow/browser-tracker, you can simply add plugins whenever you like:
import { newTracker, addPlugin } from "@snowplow/browser-tracker";
import { AdTrackingPlugin } from "@snowplow/browser-plugin-ad-tracking";
newTracker('sp1', '{{collector_url}}', {
appId: 'my-app',
plugins: [ ]
});
addPlugin({plugin: AdTrackingPlugin()});