{"_id":"5a6b684793313c005b692e1f","category":{"_id":"5a6b684793313c005b692e0a","version":"5a6b684793313c005b692e07","project":"57c87ef85754fa1700b1228d","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-11-05T21:53:37.386Z","from_sync":false,"order":2,"slug":"reference","title":"Reference"},"parentDoc":null,"user":"55e5ba046015ce1900eadb8e","project":"57c87ef85754fa1700b1228d","version":{"_id":"5a6b684793313c005b692e07","project":"57c87ef85754fa1700b1228d","__v":1,"createdAt":"2018-01-26T17:41:27.297Z","releaseDate":"2018-01-26T17:41:27.297Z","categories":["5a6b684793313c005b692e08","5a6b684793313c005b692e09","5a6b684793313c005b692e0a","5a6b684793313c005b692e0b"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"3.5.3","version":"3.5.3"},"githubsync":"","__v":0,"updates":["58b99a4c405f732300f4340c"],"next":{"pages":[],"description":""},"createdAt":"2016-03-21T09:58:46.355Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":14,"body":"The Primer SDK automatically handles install attribution for all new installs, and provides an interface to access all related information. The install attribution is data about the user that describes what brought them to your app (what link brought them to the play store). The latest attribution is the data about the user that was re-attributed (example: user clicked on a smart link after install). Most of the time, the latest attribution will be identical to the install attribution.\n\n\nOnce you receive the `PrimerAttribution` instances, you can access attribution properties:\n* whether it's a referral\n* the deep link\n* the name and key of the targeting**\n* the name of the source\n* the name of the link\n* the attribution parameters\n* the user properties of the sender\n\n\nThere are two ways to get this information\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Get Notified of Attribution\"\n}\n[/block]\nWhen the SDK syncs with our servers, it can notify your Activity about this data. You can override the `'onAttributionDataReceived()` method in the Activity.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \":::at:::Override\\nonAttributionDataReceived(PrimerAttribution installAttr, PrimerAttribution latestAttr) {\\n    PrimerLog.d(TAG, \\\"install attribution == \\\" + installAttr);\\n    PrimerLog.d(TAG, \\\"latest attribution == \\\" + latestAttr);\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Retrieve Attribution\"\n}\n[/block]\nIn case you want to get the Attribution data anytime, you can call the following methods anywhere in your code. Please note that there is a chance that the user was not attributed, and this might return null. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Get install attribution information\\n@Nullable\\nPrimerAttribution installAttr = Primer.getInstallAttribution();\\n\\n// Get latest attribution information\\n@Nullable\\nPrimerAttribution latestAttr = Primer.getLatestAttribution();\\n\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n####Smartlinks\n\nSmartlinks are intelligent links that can be given to users to redirect them to various places related to your app, track the users who click on them, and provide this information to you. One of the greatest benefits of them is that they carry through install. If a user clicks on a Smartlink who has not installed your app yet, they are directed to the Google Play to do so. Once they install, you are provided with their information from the link they installed from. The SDK automatically attributes any user who comes in through a Smartlink, so you can easily access this data in your app with the methods described above.\n\nAlso, the SDK lets you create your own Smartlinks. Any parameters you set are attached and then are passed to the app when a user installs through the link.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"String targeting = \\\"SHARES\\\";\\nJSONObject parameters = new JSONObject();\\ntry {\\n    parameters.put(\\\"name\\\", \\\"Steve\\\");\\n} catch (JSONException e) {\\n    e.printStackTrace();\\n}\\n\\nPrimer.getTargetingLink(targeting, parameters, new TargetingLinkCallback() {\\n    @Override\\n    public void onSmartLinkCreated(@Nullable String smartLink) {\\n        // Use the generated Smartlink\\n    }\\n\\n    @Override\\n    public void onError(String errorMessage) {\\n        // Here is error message if something went wrong\\n    }\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"attribution","type":"basic","title":"Attribution"}
The Primer SDK automatically handles install attribution for all new installs, and provides an interface to access all related information. The install attribution is data about the user that describes what brought them to your app (what link brought them to the play store). The latest attribution is the data about the user that was re-attributed (example: user clicked on a smart link after install). Most of the time, the latest attribution will be identical to the install attribution. Once you receive the `PrimerAttribution` instances, you can access attribution properties: * whether it's a referral * the deep link * the name and key of the targeting** * the name of the source * the name of the link * the attribution parameters * the user properties of the sender There are two ways to get this information [block:api-header] { "type": "basic", "title": "Get Notified of Attribution" } [/block] When the SDK syncs with our servers, it can notify your Activity about this data. You can override the `'onAttributionDataReceived()` method in the Activity. [block:code] { "codes": [ { "code": "@Override\nonAttributionDataReceived(PrimerAttribution installAttr, PrimerAttribution latestAttr) {\n PrimerLog.d(TAG, \"install attribution == \" + installAttr);\n PrimerLog.d(TAG, \"latest attribution == \" + latestAttr);\n}", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "Retrieve Attribution" } [/block] In case you want to get the Attribution data anytime, you can call the following methods anywhere in your code. Please note that there is a chance that the user was not attributed, and this might return null. [block:code] { "codes": [ { "code": "// Get install attribution information\n@Nullable\nPrimerAttribution installAttr = Primer.getInstallAttribution();\n\n// Get latest attribution information\n@Nullable\nPrimerAttribution latestAttr = Primer.getLatestAttribution();\n", "language": "java" } ] } [/block] ####Smartlinks Smartlinks are intelligent links that can be given to users to redirect them to various places related to your app, track the users who click on them, and provide this information to you. One of the greatest benefits of them is that they carry through install. If a user clicks on a Smartlink who has not installed your app yet, they are directed to the Google Play to do so. Once they install, you are provided with their information from the link they installed from. The SDK automatically attributes any user who comes in through a Smartlink, so you can easily access this data in your app with the methods described above. Also, the SDK lets you create your own Smartlinks. Any parameters you set are attached and then are passed to the app when a user installs through the link. [block:code] { "codes": [ { "code": "String targeting = \"SHARES\";\nJSONObject parameters = new JSONObject();\ntry {\n parameters.put(\"name\", \"Steve\");\n} catch (JSONException e) {\n e.printStackTrace();\n}\n\nPrimer.getTargetingLink(targeting, parameters, new TargetingLinkCallback() {\n @Override\n public void onSmartLinkCreated(@Nullable String smartLink) {\n // Use the generated Smartlink\n }\n\n @Override\n public void onError(String errorMessage) {\n // Here is error message if something went wrong\n }\n});", "language": "java" } ] } [/block]